QPushButton StyleSheet bug ?
-
Hello,
I have following code:const char *cHeadButtonStyle = "QPushButton#btFriends { background-color: green; }";
m_btTabMyFriends = new QPushButton(tr("btFriends"), this);
m_btTabMyFriends->setObjectName("btFriends");
m_btTabMyFriends->setStyleSheet(cHeadButtonStyle);But stylesheet doesn't work at all whatever I try.
This code works:
m_btTabMyFriends = new QPushButton(tr("btFriends"), this);
m_btTabMyFriends->setObjectName("btFriends");
m_btTabMyFriends->setStyleSheet("background-color: green;");And this one also works:
m_btTabMyFriends = new QPushButton(tr("btFriends"), this);
m_btTabMyFriends->setObjectName("btFriends");
m_btTabMyFriends->setStyleSheet("QPushButton { background-color: green; }");But this one doesn't:
m_btTabMyFriends = new QPushButton(tr("btFriends"), this);
m_btTabMyFriends->setObjectName("btFriends");
m_btTabMyFriends->setStyleSheet("QPushButton#btFriends { background-color: green; }");Is this bug in QT 5.4 related to ID selectors ?
-
Try this :
@m_btTabMyFriends->style()->polish(m_btTabMyFriends);@
-
[quote author="euchkatzl" date="1424697817"]Try this :
m_btTabMyFriends->style()->polish(m_btTabMyFriends);[/quote]
Doesn't work for me...
-
just testet your code in a simple program and it worked for me.
@int main(int argc, char *argv[])
{
QApplication a(argc, argv);QWidget w; const char *cHeadButtonStyle = "QPushButton#btFriends { background-color: green; }"; QPushButton* m_btTabMyFriends = new QPushButton("btFriends", &w); m_btTabMyFriends->setObjectName("btFriends"); m_btTabMyFriends->setStyleSheet(cHeadButtonStyle); QPushButton* m_btTabMyFriends2 = new QPushButton("btFriends", &w); m_btTabMyFriends2->setStyleSheet("QPushButton { background-color: red; }"); QHBoxLayout* lyout = new QHBoxLayout(&w); lyout->addWidget(m_btTabMyFriends); lyout->addWidget(m_btTabMyFriends2); w.show(); return a.exec();
}@
I think the problem is not in that lines.
Do you set stylesheet anywhere else ? -
Yes, your code works. But mine - doesn't.
I temporary commented out all setStyleSheet(... except one and anyway doesn't work.
What is different - I have children widgets:
main window -> children QWidget with buttons (works well) and -> children QWidget with buttons (this buttons don't work)
If I copy button code from inner QWidget that code works well in parent QWidget.What could it be ?
-
Could you try to to set one global stylesheet on your centralWidget of you main window ?
And remove all other setStylesheet declarations.That is what i did in my Application and it works.