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. Set backgroud color and Mouse hover highlighting for tabs ?[solved]
Forum Updated to NodeBB v4.3 + New Features

Set backgroud color and Mouse hover highlighting for tabs ?[solved]

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 6.4k 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.
  • V Offline
    V Offline
    vivek.narvekar
    wrote on last edited by
    #1

    Hello,

    I want to set color for the tabbar buttons. I tried using stylesheets, but, when we set stylesheet for tabbar, it is considered for the whole tabbar, and not for the individual tab button, hence, when I do mouse-hover, then entire tab bar is highlighted and not the individual tab button.

    Details of the code-

    I have overridden the enterevent for tabbar and written following code

    @setStyleSheet("QTabBar {
    background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(255, 255, 255, 255), stop:1 rgba(255, 246, 143, 255));
    color: rgb(0, 0, 255);
    }
    "); // for setting gradient yellow color @

    Then, I have overriden the leaveenvt and written following code

    @setStyleSheet("QTabBar {
    background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(255, 255, 255, 255), stop:1 rgba(200, 226, 240, 255));
    color: rgb(0, 0, 255);
    }
    "); // for setting gradient yellow color @

    Thus, this gives an effect of mouse hover, ie when the mouse enter, it turns tabbar into gradient yellow, and when the mouse leave, it turns tabbar to gradient blue.
    But actually, what i want is the individual tab button to change the color, and not the entire tab bar, as is happening in the above case.

    Thanks for any help.

    Regards
    Vivek

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rschaub
      wrote on last edited by
      #2

      this should be possible using only stylesheets, eliminating the need for subclassing the tabwidget. However, you have to alter the stylesheet slightly:

      @
      QTabBar::tab {
      // add normal style here
      }

      QTabBar::tab:hover {
      // add mouse hover style here
      }
      @

      see also "here":http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qtabwidget-and-qtabbar

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vivek.narvekar
        wrote on last edited by
        #3

        Thank you very much, I tried your solution and it worked perfectly :)

        I was referring http://qt-project.org/doc/qt-4.8/stylesheet-syntax.html for stylesheet syntax, but did not find anything related to tab. can you please let me know, where to search for stylesheet syntax, since I face such issues many times...

        Thanks a lot for helping...

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rschaub
          wrote on last edited by
          #4

          The link I've posted ("this one":http://qt-project.org/doc/qt-4.8/stylesheet-examples.html) has several examples on how to use stylesheets for the differet Qt widget classes.
          If you're looking for general stylesheet syntax and examples, maybe "this":http://www.w3schools.com/css/ will be useful to you :)

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vivek.narvekar
            wrote on last edited by
            #5

            Thanks a lot.. This was very useful .. :)

            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