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



  • 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


  • Qt Champions 2016

    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.



  • 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.


  • Qt Champions 2016

    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.



  • 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 {
    ...
    }
    


  • 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 " " ) .



  • @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);}") )
    


  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.