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 can I set Styles to a QTabwidget without overwriting existing styles in QT ?

How can I set Styles to a QTabwidget without overwriting existing styles in QT ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 3.9k 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.
  • seetharamS Offline
    seetharamS Offline
    seetharam
    wrote on last edited by
    #1

    Hi
    How can I set Styles to a QTabwidget without overwriting existing styles in QT ?
    I have designed QTabWidget in QTCreator and that will not show QTabwidget class to overwrit tabBar function .
    Please suggest me

    THanks

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

      Hi and welcome
      You can set style sheet directly in Designer.
      Right click the tabwidget and choose change style sheet.

      A style sheet is all or nothing. so if u all apply style sheet,
      it might sort of reset the look for some widgets and to fix that, you must
      supply a full stylesheet.

      1 Reply Last reply
      1
      • seetharamS Offline
        seetharamS Offline
        seetharam
        wrote on last edited by
        #3

        Thank you for your help

        Actually My problem is I have to change tab background color to gray and tab text color to red using setStyle sheet , but if I do with setStyleSheet (QTabBar::tab::selected(QTabBar { background-color : gray ; color : red }))
        it is changing the background color and text color , but here the problem is , it is overwriting existing tab styles
        suppose my tab shape is Triangular , it is changing to rectangular and border is getting changes and text font also getting changed .
        is there any way to apply only mentioned two changes and , it should not disturb existing styles.

        Thanks for your help.

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

          Hi
          That is the "all or nothing part"
          To make it look normal again, you need to set it via style sheet.

          You cannot (sadly) sort of apply on top the normal style. Once it
          uses a stylesheet. all looks must come from it. OR in other words, it
          will disturb the original look/style.

          In your case, you might be able to use palette
          https://wiki.qt.io/How_to_Change_the_Background_Color_of_QWidget
          Not sure with font color though.

          1 Reply Last reply
          1
          • Ni.SumiN Offline
            Ni.SumiN Offline
            Ni.Sumi
            wrote on last edited by Ni.Sumi
            #5

            Hi @seetharam ,

            In addition to Mr. @mrjj , I would like to add some which might help you.
            You can also apply style sheets to the object.This will override the existing style sheet only for that widget. Usually the child widget gets the style sheet from the parent widgets.

            _Object_Name1->setStyleSheet();  or 
            
            from ui->right clikc ->changeStylesheets (As Mr. @mrjj  said in the previous comment)
            #_Object_Name1 QWidget
            #_Object_Name2 QWidget {
            ...
            }
            
            1 Reply Last reply
            2
            • seetharamS Offline
              seetharamS Offline
              seetharam
              wrote on last edited by
              #6

              Hi Thank you for your Help ...

              but is there any way to get existing styles in a String
              QStting styleSheet() function is not fetching existing styles(giving " " ) .

              Ni.SumiN 1 Reply Last reply
              0
              • seetharamS seetharam

                Hi Thank you for your Help ...

                but is there any way to get existing styles in a String
                QStting styleSheet() function is not fetching existing styles(giving " " ) .

                Ni.SumiN Offline
                Ni.SumiN Offline
                Ni.Sumi
                wrote on last edited by Ni.Sumi
                #7

                @seetharam

                AFAIK, It's not possible. Lets say, if you have Object_Name1->setStylesheet("background-color:red") / in ui # Qwidget{ background-color:red }.Both will give you red back ground.
                Now if you set other setStylesheet to object_NAme1 after first style sheet some where like this Object_Name->setStyleSheet("backgound-color-blue"), then the first red back ground color will be overwritting with blue()BUT not all widget, its only to widget you set).
                As Mr. @mrjj said, it is all or nothing.

                This might help you in this way. (***I did not test this, long back I have seen this on google for my purpose)

                tabBar_1->setStyleSheet( QString("{") +tabBar_1>styleSheet()+ QString("}") + QString("QPushButton{border:url(……correct image path);}") )
                
                1 Reply Last reply
                1
                • seetharamS Offline
                  seetharamS Offline
                  seetharam
                  wrote on last edited by
                  #8

                  Thank you

                  I tried " tabBar_1->setStyleSheet( QString("{") +tabBar_1>styleSheet()+ QString("}") + QString("QPushButton{border:url(……correct image path);}") ) " also
                  StyleSheet is not giving the existing Styles . So I am getting the same behavior.

                  Thanks

                  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