[SOLVED] setStyleSheet() for tab in QTabWidget



  • Hello,

    I created a tab widget in QtDesigner and I am trying to make one of the tabs transparent to act as a spacer between my main tabs. I added the following line in the constructor of my MainWindow widget in attempt to do so:

    @ui->spacerTab->setStyleSheet("width: 1000px;" "color: transparent;" "background: transparent;");@

    For some reason nothing is happening. I even tried

    @ui->spacerTab->hide();@

    and that didn't do anything either. Is there a reason why I have no control over my spacerTab in my widget. Does anyone know of a simple way to add a spacer between a set of tabs. I do not want every tab to have a spacer just one between two groups of tabs that I have.

    Thanks


  • Moderators

    what is the type of "ui->spacerTab"? is it QTabWidget?
    You should take a look at the "stylesheet reference":http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qtabwidget-and-qtabbar.



  • [quote author="raven-worx" date="1372918890"]what is the type of "ui->spacerTab"? is it QTabWidget?
    You should take a look at the "stylesheet reference":http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qtabwidget-and-qtabbar.[/quote]

    spacerTab is a tab within my QTabWidget. I have wen through the documentation and examples and even if I copy and paste it does not work...


  • Moderators

    you mean that this is the content widget of the tab right?
    AFAIK you can't name tabs...

    The only way you can style tabs (QTabBar) is with stylesheet's sub-controls, indicators and pseudostates:
    [quote]
    Individual tabs may be styled using the ::tab subcontrol. Close buttons using the ::close-button The tabs support the :only-one, :first, :last, :middle, :previous--selected, :next-selected, :selected pseudo states.

    The :top, :left, :right, :bottom pseudo states depending on the orientation of the tabs.

    Overlapping tabs for the selected state are created by using negative margins or using the absolute position scheme.

    The tear indicator of the QTabBar is styled using the ::tear subcontrol.

    QTabBar used two QToolButtons for its scrollers that can be styled using the QTabBar QToolButton selector. To specify the width of the scroll button use the ::scroller subcontrol.

    The alignment of the tabs within the QTabBar is styled using the alignment property.

    Warning:

    To change the position of the QTabBar within a QTabWidget, use the tab-bar subcontrol (and set subcontrol-position).
    [/quote]



  • [quote author="raven-worx" date="1372938959"]you mean that this is the content widget of the tab right?
    AFAIK you can't name tabs...

    The only way you can style tabs (QTabBar) is with stylesheet's sub-controls, indicators and pseudostates:
    [quote]
    Individual tabs may be styled using the ::tab subcontrol. Close buttons using the ::close-button The tabs support the :only-one, :first, :last, :middle, :previous--selected, :next-selected, :selected pseudo states.

    The :top, :left, :right, :bottom pseudo states depending on the orientation of the tabs.

    Overlapping tabs for the selected state are created by using negative margins or using the absolute position scheme.

    The tear indicator of the QTabBar is styled using the ::tear subcontrol.

    QTabBar used two QToolButtons for its scrollers that can be styled using the QTabBar QToolButton selector. To specify the width of the scroll button use the ::scroller subcontrol.

    The alignment of the tabs within the QTabBar is styled using the alignment property.

    Warning:

    To change the position of the QTabBar within a QTabWidget, use the tab-bar subcontrol (and set subcontrol-position).
    [/quote][/quote]

    Yes, you are right, it is the content of a page within the QTabWidget. But, I do not want to reposition the entire tab bar. I want to reposition an individual tab to be separated by an inch or so from my main tabs. I dont think you can position individual tabs in the tab bar so I wanted a way to add a tab between and make that one transparent and non-clickable so that it gives the effect of a space between my tabs.



  • Figured it out myself. I was missing placing it in a stylesheet:

    @this->setStyleSheet("QTabBar::tab:disabled {width: 1000px; color: transparent; background: transparent;}");@


Log in to reply
 

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