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 QToolBar color without losing the blue QToolButton hover effect
QtWS25 Last Chance

How to set QToolBar color without losing the blue QToolButton hover effect

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

    Everytime I try to set the background color of my toolbar I lose the blue hover effect of the Actions/ToolButtons.
    I tried with setting a new stylesheet and also with appending to the existing one.

    When using one of the following, I lose the hover effect:

    ui->toolBar->setStyleSheet("background-color: rgba(200, 200, 200, 255);");
    //or
    ui->toolBar->setStyleSheet(ui->toolBar->styleSheet().append("background-color: rgba(200, 200, 200, 255);"));
    

    When adding the hover part, I use the background color of the Toolbar instead.

    ui->toolBar->setStyleSheet("background-color: rgba(200, 200, 200, 255); QToolButton:hover {background-color: blue};");
    //or
    ui->toolBar->setStyleSheet(ui->toolBar->styleSheet().append("background-color: rgba(200, 200, 200, 255); QToolButton:hover {background-color: blue};"));
    

    I tried playing with Palette in Designer but that did not work at all.

    What is the right way of doing this?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Fuel
      wrote on last edited by
      #2

      @Megamouse said in How to set QToolBar color without losing the blue QToolButton hover effect:

      ui->toolBar->setStyleSheet("background-color: rgba(200, 200, 200, 255);");

      Use

      ui->toolBar->setStyleSheet("QToolBar { background-color: rgba(200, 200, 200, 255); }");
      

      maybe that helps.

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

        Hi
        Style sheet are cascading
        so when u set on ToolBar with no Type specifier/name it also affects buttons
        So what @Fuel suggest, should work as its using typename.

        1 Reply Last reply
        0
        • MegamouseM Offline
          MegamouseM Offline
          Megamouse
          wrote on last edited by
          #4

          amazing !

          it works, thank you @Fuel @mrjj

          I did not know I could set a style for only the target object by using its own typename.

          thanks again

          mrjjM 1 Reply Last reply
          0
          • MegamouseM Megamouse

            amazing !

            it works, thank you @Fuel @mrjj

            I did not know I could set a style for only the target object by using its own typename.

            thanks again

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Megamouse
            Super :)
            And to the typename, you can also add instance name (object name)
            QPushButton#evilButton { background-color: red }
            Type QPushButton but only named evilButton
            http://doc.qt.io/qt-5/stylesheet-examples.html

            You can apply stylesheet to QApplication.
            That is the highest parent you can get and it will affect most.

            1 Reply Last reply
            1

            • Login

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