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 change button style sheet?
Forum Updated to NodeBB v4.3 + New Features

How to change button style sheet?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 466 Views 3 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.
  • V Offline
    V Offline
    Victor Delattre
    wrote on last edited by
    #1

    I know we can change style sheet of a button like in css but I don't know how to access the style sheet
    I want to use this: a6222350-142e-4e38-ac90-6a7957b340cf-image.png

    But I only know this: 8cadc06d-8e68-4c7a-9419-130fd41b8b8f-image.png

    I just don't know how to access to the part when you can write like in css?
    Please help me !

    Pl45m4P 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      If you want some sort of editable stylesheet, you should make it's content a member variable so you can then modify it to match what you want.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • V Victor Delattre

        I know we can change style sheet of a button like in css but I don't know how to access the style sheet
        I want to use this: a6222350-142e-4e38-ac90-6a7957b340cf-image.png

        But I only know this: 8cadc06d-8e68-4c7a-9419-130fd41b8b8f-image.png

        I just don't know how to access to the part when you can write like in css?
        Please help me !

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #3

        @Victor-Delattre

        What do you mean? Variable RGB colors instead of yellow? Where exactly is the problem?
        The stylesheet can be treated as a regular QString, so you can make use of QString::args.

        int value = 255;
        QString style("%1").args(value);
        

        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        1
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi

          Its very unclear what you ask about , but after some coffee I realized you may be asking how to use
          same syntax as in the first screen shot

          For that you can use c++ raw strings syntax
          the R"()" part.

          This allows you to have any text directly AS IS

          
          QString Sheet = R"(
          QPushButton#pushButton {
              background-color: yellow;
          }
          QPushButton#pushButton:pressed {
              background-color: rgb(224, 0, 0);     
          }
          QPushButton#pushButton:hover {
              background-color: rgb(224, 255, 0);
          })";
          
          setStyleSheet(sheet);
          
          
          
          V 1 Reply Last reply
          1
          • mrjjM mrjj

            Hi

            Its very unclear what you ask about , but after some coffee I realized you may be asking how to use
            same syntax as in the first screen shot

            For that you can use c++ raw strings syntax
            the R"()" part.

            This allows you to have any text directly AS IS

            
            QString Sheet = R"(
            QPushButton#pushButton {
                background-color: yellow;
            }
            QPushButton#pushButton:pressed {
                background-color: rgb(224, 0, 0);     
            }
            QPushButton#pushButton:hover {
                background-color: rgb(224, 255, 0);
            })";
            
            setStyleSheet(sheet);
            
            
            
            V Offline
            V Offline
            Victor Delattre
            wrote on last edited by
            #5

            @mrjj THANK YOU :))
            Helped a lot!

            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