Z-order of QTab in a QTabWidget
Hi. I’m trying to change the Z-order of a tabs in a QTabWidget.
The selected QTab is on top of the other tabs, but from left to right, the tabs goes from under to the top. I Mean, the first tab is under the second tab, that is under the third tab, etc.. We can see this order if we are using a negative margin to get the tabs overlapping each other.
I need to change this order to get my first tab over the second one and the second one over the third one.. so an order from top to under..
I tried the css z-index properties without success and i did’nt find any documentation on how to change this z-order. Is somebody having an idea how to change that?
I also tried to change the creating order of these tabs and also the way they are added to the QTabWidget with a insert (QTabWidget.insertTab()) at position 0 instead of just adding tabs with QTabWidget.addTab().. always the same thing..
here a picture that explain the problem:
11 replies
TabWidget.h
- {
- Q_OBJECT
- public:
- private slots:
- void tabChanged( int tabNumber );
- };
TabWidget.cpp
- {
- connect( this,
- SIGNAL( currentChanged( int ) ),
- SLOT( tabChanged( int ) ) );
- leftShadow_->setObjectName( "leftshadow" ); // with object name you can easily assign a stylesheet
- leftShadow_->setFixedWidth( 10 ); // don't remeber why i did this constant. I think it should be in the stylesheet
- leftShadow_->setFixedHeight( tabBar()->height() );
- rightShadow_->setObjectName( "rightshad--ow" );
- rightShadow_->setFixedWidth( 10 );
- rightShadow_->setFixedHeight( tabBar()->height() );
- }
- void TabWidget::tabChanged( int tabNumber )
- {
- if( tabNumber == 0 )
- {
- leftShadow_->hide();
- }
- else
- {
- leftShadow_->setFixedHeight( tabRect.height() - 4 ); // this '4' is the difference between heights of selected and unselected tabs
- leftShadow_->move( leftPos.x() - leftShadow_->width(),
- leftPos.y() - leftShadow_->height() + 1 );
- leftShadow_->show();
- }
- if( tabNumber == ( count() - 1 ) )
- {
- rightShadow_->hide();
- }
- else
- {
- rightShadow_->setFixedHeight( tabRect.height() - 4 );
- rightShadow_->move( rightPos.x(),
- rightPos.y() - rightShadow_->height() + 1 );
- rightShadow_->show();
- }
- }
- {
- Q_UNUSED( event )
- tabChanged( currentIndex() );
- }
Gerolf, ok. I’ll do it today.
And here is the stylesheet:
- #leftshadow
- {
- background-color: qlineargradient(spread:pad,x1:0.312,y1:0.419545,x2:1,y2:0,stop:0 rgba(0, 0, 0, 0),stop:0.817778 rgba(80, 80, 80, 193),stop:1 rgba(80, 80, 80, 255));
- }
- #rightshadow
- {
- background-color: qlineargradient(spread:pad,x1:0.680,y1:0.419545,x2:0,y2:0,stop:0 rgba(0, 0, 0, 0),stop:0.817778 rgba(80, 80, 80, 193),stop:1 rgba(80, 80, 80, 255));
- }
Here is the snippet [developer.qt.nokia.com] in the wiki.
You must log in to post a reply. Not a member yet? Register here!



