PDA

View Full Version : Switching off all tabs in QTabWidget



Gopala Krishna
30th August 2006, 11:47
Hello all,
I had implemented my own vertical tabwidget for Qt3.3 using QPushButton & QWidgetStack and had given the option to switch off all tabs i.e all tabbuttons could be off at a time(hiding the widgetstack). This behaviour was mimicked from KDevelop and KMdi.
But I recently updated myself to Qt4.1( aslo experimenting with Qt4.2) and came across QTabWidget::setTabPosition() which supports vertical tabbars.
But the problem is I am unable to turn off all tabs :(
I want the the widget(in tabwidget) to be hidden and all tabs to be turned off when an active tab is clicked again.

So how can I subclass QTabWidget and get the above functionality ?

jacek
30th August 2006, 12:48
void SomeClass::on_tabWidget_currentChanged( int currentIndex )
{
static int prevIndex = -1;
QWidget *prev = _ui.tabWidget->widget( prevIndex );
if( prev != 0 ) {
prev->setEnabled( false );
}

QWidget *current = _ui.tabWidget->widget( currentIndex );
if( current != 0 ) {
current->setEnabled( true );
}

prevIndex = currentIndex;
}

Gopala Krishna
30th August 2006, 15:16
Hi Jacek, thanks for your immediate reply but I didn't get what I wanted. I tried your code but it behaves as normal QTabWidget.
May be the 2 screenshots will help
tab1.png : With one of tab chosen
tab2.png : With all tabs off

jacek
30th August 2006, 15:30
OK, now I see what you mean by "off". Unfortunately in QTabWidget one of the tabs is always active, so to do this you will have to use QStackedWidget and some custom widget that will imitate the tab bar.

Gopala Krishna
30th August 2006, 15:45
Hi Jacek,
Thats why I had to come with custom code.
But anyway , can't all tabs be made to be inactive even in QTabBar ?

Is any improvements ,about this, going on in Qt4.2 ?

jacek
30th August 2006, 16:21
can't all tabs be made to be inactive even in QTabBar ?
Unfortunately not, it always has one of the tabs active.

Actually you are after a bit different widget --- something like KMdiDockContainer.

Gopala Krishna
30th August 2006, 16:28
Thanks for your reply.


Actually you are after a bit different widget --- something like KMdiDockContainer.
But unfortunately I am only after Qt only solution. :(

elcuco
30th August 2006, 18:10
you can look for the QStackedWidget and hide it on demand. See the assistant code for some details (look to the tab widget implementation in that application)
ideality -> http://www.qtcentre.org/forum/f-qt-software-16/t-announce-ideality-001-library-3286.html