Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPushButton StyleSheet bug ?
Qt 6.11 is out! See what's new in the release blog

QPushButton StyleSheet bug ?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    ksubox
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • E Offline
      E Offline
      euchkatzl
      wrote on last edited by
      #2

      Try this :

      @m_btTabMyFriends->style()->polish(m_btTabMyFriends);@

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        [quote author="euchkatzl" date="1424697817"]Try this :

        m_btTabMyFriends->style()->polish(m_btTabMyFriends);[/quote]

        Doesn't work for me...

        1 Reply Last reply
        0
        • E Offline
          E Offline
          euchkatzl
          wrote on last edited by
          #4

          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 ?

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            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 ?

            1 Reply Last reply
            0
            • E Offline
              E Offline
              euchkatzl
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt
              • Unsolved