Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

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

    General and Desktop
    3
    8
    2913
    Loading More Posts
    • 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.
    • seetharam
      seetharam last edited by

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 1
        • seetharam
          seetharam last edited by

          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 Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion last edited by

            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 Reply Quote 1
            • Ni.Sumi
              Ni.Sumi last edited by Ni.Sumi

              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 Reply Quote 2
              • seetharam
                seetharam last edited by

                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.Sumi 1 Reply Last reply Reply Quote 0
                • Ni.Sumi
                  Ni.Sumi @seetharam last edited by Ni.Sumi

                  @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 Reply Quote 1
                  • seetharam
                    seetharam last edited by

                    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 Reply Quote 0
                    • First post
                      Last post