Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. id selector not working in qss in qt 5.7

id selector not working in qss in qt 5.7

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.3k Views
  • 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.
  • AmoghA Offline
    AmoghA Offline
    Amogh
    wrote on last edited by
    #1

    I have a class called mywidget in which i am creating multiple objects of Qpushbutton and i am maintaining a separate qss stylesheet. I am trying to have a separate design for each pushbutton, as per the document "QPushbutton#objectname1{ color:Red}" and "QPushbutton#objectname2{ color:Blue}" should work, but it is not working, is there any other way please help.

    J.HilkJ 1 Reply Last reply
    0
    • AmoghA Amogh

      I have a class called mywidget in which i am creating multiple objects of Qpushbutton and i am maintaining a separate qss stylesheet. I am trying to have a separate design for each pushbutton, as per the document "QPushbutton#objectname1{ color:Red}" and "QPushbutton#objectname2{ color:Blue}" should work, but it is not working, is there any other way please help.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      hi @Amogh

      I haven't yet heard of an instance where that method failed.

      can you show the button and stylesheet creation ?


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1
      • AmoghA Offline
        AmoghA Offline
        Amogh
        wrote on last edited by
        #3

        Mywidget.cpp
        MyWidget::MyWidget(QWidget *parent)
        : QWidget(parent)
        {
        m_b1= new QPushButton("Submit");
        m_b2= new QPushButton("Cancel");
        .....
        ....
        .....
        QFile file(":/new/xyz.qss");
        file.open(QFile::ReadOnly);
        stylesheet = QLatin1String(file.readAll());
        qApp->setStyleSheet(stylesheet);
        }
        .qss file
        QPushButton#m_b1{
        background-color: blue;
        border-width: 2px;
        border-color: darkkhaki;
        border-style: solid;
        border-radius: 5;
        padding: 3px;
        min-width: 9ex;
        min-height: 2.5ex;
        }
        QPushButton#m_b2{
        background-color: Red;
        border-width: 2px;
        border-color: darkkhaki;
        border-style: solid;
        border-radius: 5;
        padding: 3px;
        min-width: 9ex;
        min-height: 2.5ex;
        }

        1 Reply Last reply
        1
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          Variable names are lost during compilation you have to call setObjectName
          m_b1->setObjectName(QStringLiteral("m_b1"));

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          5
          • AmoghA Offline
            AmoghA Offline
            Amogh
            wrote on last edited by
            #5

            @VRonin Thank you soo much! It works now :)

            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 Extensions
            • Unsolved