PDA

View Full Version : How do you set style sheets for various widgets?



paie
9th August 2011, 20:15
I have had very limited success with widget->setStyleSheet.

I'm certain that it's "user error", but part of the problem is I just don't know where to go to get a list of valid properties for any given widget.

For example, what are all the valid properties for QPushButton?

How do I set a QPlainTextEdit box to have a sunken look?

I have tried things like this ...

bbStyle = "color: aqua; background-color: black; "
"border-style: outaet; border-color: green;"
"border-width: 2px";

this->setStyleSheet(QString(bbStyle));


... but the only thing that works in that example is the background and foreground colors.

Lykurg
9th August 2011, 21:35
I just don't know where to go to get a list of valid properties for any given widget.Ehm, have you ever heard of the DOCUMENTATION of Qt? Be tough and use the search inside Qt Assistant and try it with "style sheets".

As a hint: the qproperty-fooBar option could be useful for you.


EDIT: And by the way if you correct your typo (it is outset) your css works fine.

paie
10th August 2011, 00:18
Well, fair enough, but I have been all over the documentation and, maybe it's just me, but I can't locate one place where all the properties/styles, and what they do, are listed for the various features and how they map to the different widgets, that is, what applies to one widget but not on another.

You were also correct about my fumble-finger typo, and I did see the features expressed when I fixed that, but not as I would have hoped. I lost the background and foreground colors, and I don't think it's a typo, this time.
:)


bbStyle[0] = "color: aqua; background-color: black"
"border-style: outset; border-color: green;"
"border-width: 2px";

bbStyle[1] = "color: black; background-color: aqua"
"border-style: outset; border-color: green;"
"border-width: 2px";
:
:
void BitButton::setState(int state)
{
bbState = state;
this->setText(QString::number(state));
this->setStyleSheet(bbStyle[state]);
}


As you can see, what I'm looking for is a pushbutton that toggles its color every time it's pressed. I subclassed QBitbutton to do this. When I get the button to change color, the asthetics are lacking. When I add some dimension, I lose the color. I remember reading in the docs that some of these properties conflict, but it wasn't clear to me which ones, which is why I'm looking for a table or list that explains these things.