Unsolved setStyleSheet - What is it for?
-
Thanks for the answer.
Yes, I’ve noticed that it looks like CSS although I’ve never done such web programming.
I guess it is good for someone who knows CSS but it isn’t appropriate for application programmers.
I had to search the web to figure out what I am suppose to give to setStyleSheet() and go through a few pages.“For performance reasons it's best to avoid such small inline stylesheets.”
==I don’t think I have a choice. It is only the style of QLineEdit and QPushButton that I want to change.
I am only doing this since for some reason, when I run my app on Linuxes where Qt Creator is not installed, the QLineEdit does not have an entourage.
They just look like white rectangles and it is hard to see them.
I work on Kubuntu 20.10 and I test on Kubuntu 18.04 and Kubuntu 20.10 and others.As for the QPushButton, the height of the buttons were not right or something. They looked too short. The call to setStyleSheet() helped with this one.
I don’t need anything custom and dynamic.
The program just needs to start and just look good. -
@stretchthebits said:
I had to search the web to figure out what I am suppose to give to setStyleSheet() and go through a few pages.
The syntax is described here and a reference for each widget are listed here.
I don’t think I have a choice.
You do. You can decide not to use stylesheets ;)
the QLineEdit does not have an entourage
Maybe its frame was turned off?
As for the QPushButton, the height of the buttons were not right or something
Make sure they are in a proper layout. Also you can change the min/max height of a button, for example setMinimumHeight.
-
I looked at those pages but apparently, that wasn’t enough for me.
I was calling
pedit->setStyleSheet(some string)
and nothing was happening.so I guess there were run time errors.
That’s the problem. If the string I give to setStyleSheet() is bad, can it tell me it is bad and which word in the string is bad?Another problem is that the code would compile. The C++ compiler cannot analyze the text I gave to setStyleSheet().
For example, if I write
pedit=new QineEdit(this);the compiler would tell me there is a problem with that line.
I get rid of a lot of typing mistakes this way: missing colon and missing parenthesis and much more.@Chris-Kawa said in setStyleSheet - What is it for?:
Maybe its frame was turned off?
I turned on the frame with a member function call. I think it was
pedit->setFrame........
but it had no effect.
then, when I started to use setStyleSheet() and this had a real effect on how the edit boxes looked.Thanks for the setMinimumHeight(). I wasn’t aware of that function. Perhaps it would have solved the button height issue.
-
@stretchthebits
The answer to all of this is, I'm afraid, no, Qt will neither tell you if there is a mistake in your stylesheet, nor if there is where it lies. In common with, say, HTML page handling, badly formed style directives are simply ignored by the engine.On an HTML page in a browser, like Chrome, there are nice "Developer Tools" which allow you to interactively investigate your styles and play with them responsively. Sadly I am aware that Qt does not offer such an interactive examiner, which I miss, but that's how it is.
-
@JonB said in setStyleSheet - What is it for?:
Sadly I am aware that Qt does not offer such an interactive examiner, which I miss, but that's how it is.
At least in QtDesigner's
Stylesheet
"mode", "tab" or whatever it is, it checks if your stylesheet string is a valid stylesheet but unfortunately this does not work dynamically when changing stylesheet in your code (only for preset styles in QtDesigner). -
@Pl45m4
I understand what you are saying, and that is a good point. At least the OP might consider pasting any dynamic stylesheet used at run-time into that box to see what Designer makes of it, better than nothing.However, for the record, this is nothing like/to do with what I was talking about using in a web browser. All the browsers offer "Development Tools" interface. That does something totally different: you can view and click your page, either visually or in HTML, and be shown where the elements are, and what styles from where are being applied/overridden. Even nicer, you can interactively check/uncheck boxes for each and every individual style attribute on every element to see its effect, you can modify the styles while you are looking at them and see the response, etc. Fully interactive.
As someone who did HTML/JS/CSS for years, I found this an invaluable tool in getting my layouts, styles and so on sorted out. I have thought for years how nice it would be if Qt offered something similar and friendly for its desktop widgets and styles, but did not find anything acceptable.
-
@JonB
Hi
Just as a note.
https://doc.qt.io/GammaRay/
does add a sort of "Developer Tools" to Qt. -
@mrjj
I thought someone was going to say this! And again a good point :)However, I tried to use that a while ago, and just didn't get anywhere. I don't quite recall why. Was it way too big and complicated complicated? Did it just not install or work for me? Did it not work when I was programming in Python/PyQt?
So, honest answer: Do you use it? Regularly? :)
-
@JonB
Nope. Didn't really uses it as it wants cmake... and I agree way too complicated to get running but does provide
a huge array of tools.
If it was build into Creator (not sure thats even possible) it would be another story.Edit:
They do supply prebuilds now so maybe its easier than before. -
@JonB said in setStyleSheet - What is it for?:
However, for the record, this is nothing like/to do with what I was talking about using in a web browser. All the browsers offer "Development Tools" interface. That does something totally different: you can view and click your page, either visually or in HTML, and be shown where the elements are, and what styles from where are being applied/overridden. Even nicer, you can interactively check/uncheck boxes for each and every individual style attribute on every element to see its effect, you can modify the styles while you are looking at them and see the response, etc. Fully interactive.
As someone who did HTML/JS/CSS for years, I found this an invaluable tool in getting my layouts, styles and so on sorted out. I have thought for years how nice it would be if Qt offered something similar and friendly for its desktop widgets and styles, but did not find anything acceptable.Yeah true, but integrating such feature would make the IDE much more "complex".
I'm thinking of something like theQt::Color
behavior in QtCreator: If you hover over a validQColor
string / enum value, a label appears, showing the corresponding color. That would be awesome to have withQWidget
styles. So that a new window / popup shows up, showing what you can expect from your code (matching the widget you are using the stylesheet on). -
@Pl45m4 said in setStyleSheet - What is it for?:
Yeah true, but integrating such feature would make the IDE much more "complex".
I don't mean to harp on. But again for the record I --- and probably the OP --- am interested in runtime support for such features, not (particularly) design-time. Like @mrjj's GammaRay or a web browser provides. 'Nuff said :)