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. How to set styleSheet to all QPushButtons?

How to set styleSheet to all QPushButtons?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 327 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.
  • T Offline
    T Offline
    TomNow99
    wrote on last edited by
    #1

    Hello.

    In CSS I have something like:

    h1
    {
         color:red;
    }
    

    which set text color in all h1 to red.

    I would like the same in QT ( I don't want use QML ). When I set:

    pushButton1->setStyleSheet("QPushButton {color:red;}");
    

    I set the text color only on this "pushButton1". How can I set styleSheet to all QPushButtons in my App ( using code - not uimainWindow )?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on last edited by
      #2

      You can use QApplication::setStyleSheet, in the main.cpp, like this

      QApplication app(argc, argv);
      app.setStyleSheet("QPushButton {color:red;}");
      
      1 Reply Last reply
      3
      • T Offline
        T Offline
        TomNow99
        wrote on last edited by TomNow99
        #3

        @Bonnie And extra question:

        Is there any way to add names to QWidgets?

        I think about this:

        HTML and CSS:

        <div id="myDiv"> </div>
        

        and next

        #myDiv
        {
            height: 500px;
            width: 500 px;
        }
        

        So I would like use #Widget

        J.HilkJ 1 Reply Last reply
        0
        • T TomNow99

          @Bonnie And extra question:

          Is there any way to add names to QWidgets?

          I think about this:

          HTML and CSS:

          <div id="myDiv"> </div>
          

          and next

          #myDiv
          {
              height: 500px;
              width: 500 px;
          }
          

          So I would like use #Widget

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

          @TomNow99 sure, for example:

          QPushButton#btnHome { border: 1px solid rgb(87,117,131);}

          the text after the # has to be the objectName -property of your widget


          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
          2
          • T Offline
            T Offline
            TomNow99
            wrote on last edited by
            #5

            @J-Hilk @Bonnie Perfect! Thank you

            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