Henry Blue Heeler
28th December 2013, 05:20
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?
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;
}
}
}
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?
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;
}
}
}