diff --git a/examples/widgets/mainwindows/mainwindow/toolbar.cpp b/examples/widgets/mainwindows/mainwindow/toolbar.cpp index 66f26d7a72..d73c12f50d 100644 --- a/examples/widgets/mainwindows/mainwindow/toolbar.cpp +++ b/examples/widgets/mainwindows/mainwindow/toolbar.cpp @@ -37,8 +37,9 @@ static QPixmap genIcon(const QSize &iconSize, const QString &, const QColor &col static QPixmap genIcon(const QSize &iconSize, int number, const QColor &color, qreal pixelRatio) { return genIcon(iconSize, QString::number(number), color, pixelRatio); } -ToolBar::ToolBar(const QString &title, QWidget *parent) - : QToolBar(parent) +ToolBar::ToolBar(const QString &title, QMainWindow *mainWindow) + : QToolBar(mainWindow) + , mainWindow(mainWindow) , spinbox(nullptr) , spinboxAction(nullptr) { @@ -161,9 +162,6 @@ ToolBar::ToolBar(const QString &title, QWidget *parent) void ToolBar::updateMenu() { - QMainWindow *mainWindow = qobject_cast(parentWidget()); - Q_ASSERT(mainWindow); - const Qt::ToolBarArea area = mainWindow->toolBarArea(this); const Qt::ToolBarAreas areas = allowedAreas(); @@ -267,9 +265,6 @@ void ToolBar::place(Qt::ToolBarArea area, bool p) if (!p) return; - QMainWindow *mainWindow = qobject_cast(parentWidget()); - Q_ASSERT(mainWindow); - mainWindow->addToolBar(area, this); if (allowedAreasActions->isEnabled()) { @@ -309,8 +304,5 @@ void ToolBar::placeBottom(bool p) void ToolBar::insertToolBarBreak() { - QMainWindow *mainWindow = qobject_cast(parentWidget()); - Q_ASSERT(mainWindow); - mainWindow->insertToolBarBreak(this); } diff --git a/examples/widgets/mainwindows/mainwindow/toolbar.h b/examples/widgets/mainwindows/mainwindow/toolbar.h index 14eca61684..0030adbe23 100644 --- a/examples/widgets/mainwindows/mainwindow/toolbar.h +++ b/examples/widgets/mainwindows/mainwindow/toolbar.h @@ -16,7 +16,7 @@ class ToolBar : public QToolBar Q_OBJECT public: - explicit ToolBar(const QString &title, QWidget *parent); + explicit ToolBar(const QString &title, QMainWindow *mainWindow); QMenu *toolbarMenu() const { return menu; } @@ -45,6 +45,8 @@ private: void allow(Qt::ToolBarArea area, bool allow); void place(Qt::ToolBarArea area, bool place); + QMainWindow *mainWindow; + QSpinBox *spinbox; QAction *spinboxAction;