I'm trying to use the same toolbar with a parent QMainWindow and its children QMainWindows.
Same actions, same stylesheet, same icons, etc.
The following likely violates all sense of Qt decency, but it kind of works, but only for the first few instantiations of the child QMainWindows.
I know I'm just using pointers, but is there a better way other than painstakingly building a new toolbar for each child QMainWindow?
ui(new Ui::SubWin)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
foreach
( QWidget* widget, qApp
->allWidgets
() ) {
if ( QToolBar* mainTB
= qobject_cast<QToolBar
*>
( widget
) ) {
if( mainTB->objectName() == "mainToolBar" )
{
this->addToolBar(Qt::TopToolBarArea, NewTB );
NewTB->setMovable(false);
NewTB->setStyleSheet(mainTB->styleSheet());
NewTB->addActions(mainTB->actions());
}
break;
}
}
}
SubWin::SubWin(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::SubWin)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
foreach ( QWidget* widget, qApp->allWidgets() )
{
if ( QToolBar* mainTB = qobject_cast<QToolBar*>( widget ) )
{
if( mainTB->objectName() == "mainToolBar" )
{
QToolBar *NewTB = new QToolBar("New Tool Bar", 0);
this->addToolBar(Qt::TopToolBarArea, NewTB );
NewTB->setMovable(false);
NewTB->setStyleSheet(mainTB->styleSheet());
NewTB->addActions(mainTB->actions());
}
break;
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks