If you're creating the QTabWidget and QPushButtons yourself (regardless if you're using Qt Designer or directly by code) then you can subclass them.
By subclassing the QTabWidget, you can add a slot to it that receives the 'clicked' signals from the buttons.
By subclassing the QPushButtons, you can add a member property that indicates the tab index that you should switch to.
The QTabWidget knows the widgets that you're adding as pages to it (or you can retrieve them with widget(index) if they are already added), so its new slot can easily be connected to each of the signals from the buttons since you have visibility of them.
The slot could be something like this:
void MyTabWidget::onButtonClick()
{
MyPushButton* button = qobject_cast< MyPushButton* >( sender() );
setCurrentIndex( button.getDesiredIndex() );
}
void MyTabWidget::onButtonClick()
{
MyPushButton* button = qobject_cast< MyPushButton* >( sender() );
setCurrentIndex( button.getDesiredIndex() );
}
To copy to clipboard, switch view to plain text mode
If you're using Qt Designer, you'll need promote the QTabWidget and the QPushButtons to their corresponding subclasses.
EDIT: Forgot the scope operator, and changed from static_cast to qobject_cast as the below suggestion.
Bookmarks