diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 3c5469f128..fcb74370c7 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -3385,6 +3385,14 @@ void QHeaderView::initStyleOption(QStyleOptionHeader *option) const option->section = 0; } +void QHeaderView::initStyleOption(QStyleOptionFrame *option) const +{ + // The QFrame version is only here to avoid compiler warnings. + // If invoked (it can be invoked with QFrame *f = headerview; f->initStyleOption()), + // and here we just pass it on to the frame version. + QFrame::initStyleOption(option); +} + bool QHeaderViewPrivate::isSectionSelected(int section) const { int i = section * 2; diff --git a/src/widgets/itemviews/qheaderview.h b/src/widgets/itemviews/qheaderview.h index 6cfa9a8bf0..6bbfb8449c 100644 --- a/src/widgets/itemviews/qheaderview.h +++ b/src/widgets/itemviews/qheaderview.h @@ -230,12 +230,14 @@ protected: QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers) override; void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags) override; QRegion visualRegionForSelection(const QItemSelection &selection) const override; - void initStyleOption(QStyleOptionHeader *option) const; + virtual void initStyleOption(QStyleOptionHeader *option) const; friend class QTableView; friend class QTreeView; private: + void initStyleOption(QStyleOptionFrame *option) const override; + // ### Qt6: make them protected slots in QHeaderViewPrivate Q_PRIVATE_SLOT(d_func(), void _q_sectionsRemoved(const QModelIndex &parent, int logicalFirst, int logicalLast)) Q_PRIVATE_SLOT(d_func(), void _q_sectionsAboutToBeMoved(const QModelIndex &sourceParent, int logicalStart, int logicalEnd, const QModelIndex &destinationParent, int logicalDestination)) diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp index c9753f5f51..154957eea3 100644 --- a/src/widgets/widgets/qabstractspinbox.cpp +++ b/src/widgets/widgets/qabstractspinbox.cpp @@ -1629,6 +1629,8 @@ void QAbstractSpinBoxPrivate::init() edit->setValidator(validator); QStyleOptionSpinBox opt; + // ### This is called from the ctor and thus we shouldn't call initStyleOption yet + // ### as we only call the base class implementation of initStyleOption called. q->initStyleOption(&opt); spinClickTimerInterval = q->style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatRate, &opt, q); spinClickThresholdTimerInterval = q->style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatThreshold, &opt, q); diff --git a/src/widgets/widgets/qabstractspinbox.h b/src/widgets/widgets/qabstractspinbox.h index 87d46c7326..50c139e066 100644 --- a/src/widgets/widgets/qabstractspinbox.h +++ b/src/widgets/widgets/qabstractspinbox.h @@ -160,7 +160,7 @@ protected: void timerEvent(QTimerEvent *event) override; void paintEvent(QPaintEvent *event) override; void showEvent(QShowEvent *event) override; - void initStyleOption(QStyleOptionSpinBox *option) const; + virtual void initStyleOption(QStyleOptionSpinBox *option) const; QLineEdit *lineEdit() const; void setLineEdit(QLineEdit *edit); diff --git a/src/widgets/widgets/qcheckbox.h b/src/widgets/widgets/qcheckbox.h index 80cb22b82e..bb0f303235 100644 --- a/src/widgets/widgets/qcheckbox.h +++ b/src/widgets/widgets/qcheckbox.h @@ -81,7 +81,7 @@ protected: void nextCheckState() override; void paintEvent(QPaintEvent *) override; void mouseMoveEvent(QMouseEvent *) override; - void initStyleOption(QStyleOptionButton *option) const; + virtual void initStyleOption(QStyleOptionButton *option) const; private: diff --git a/src/widgets/widgets/qcombobox.h b/src/widgets/widgets/qcombobox.h index 1e518fb2c0..75dbb1183d 100644 --- a/src/widgets/widgets/qcombobox.h +++ b/src/widgets/widgets/qcombobox.h @@ -230,7 +230,7 @@ protected: void contextMenuEvent(QContextMenuEvent *e) override; #endif // QT_NO_CONTEXTMENU void inputMethodEvent(QInputMethodEvent *) override; - void initStyleOption(QStyleOptionComboBox *option) const; + virtual void initStyleOption(QStyleOptionComboBox *option) const; protected: diff --git a/src/widgets/widgets/qdatetimeedit.h b/src/widgets/widgets/qdatetimeedit.h index e2dfb94b19..a1d9be1088 100644 --- a/src/widgets/widgets/qdatetimeedit.h +++ b/src/widgets/widgets/qdatetimeedit.h @@ -193,7 +193,7 @@ protected: StepEnabled stepEnabled() const override; void mousePressEvent(QMouseEvent *event) override; void paintEvent(QPaintEvent *event) override; - void initStyleOption(QStyleOptionSpinBox *option) const; + void initStyleOption(QStyleOptionSpinBox *option) const override; QDateTimeEdit(const QVariant &val, QMetaType::Type parserType, QWidget *parent = nullptr); private: diff --git a/src/widgets/widgets/qdial.h b/src/widgets/widgets/qdial.h index 1db1f9bb07..9abea5bf45 100644 --- a/src/widgets/widgets/qdial.h +++ b/src/widgets/widgets/qdial.h @@ -90,7 +90,7 @@ protected: void mouseMoveEvent(QMouseEvent *me) override; void sliderChange(SliderChange change) override; - void initStyleOption(QStyleOptionSlider *option) const; + virtual void initStyleOption(QStyleOptionSlider *option) const; private: diff --git a/src/widgets/widgets/qdockwidget.h b/src/widgets/widgets/qdockwidget.h index d553407fb5..69c5a6447a 100644 --- a/src/widgets/widgets/qdockwidget.h +++ b/src/widgets/widgets/qdockwidget.h @@ -116,7 +116,7 @@ protected: void closeEvent(QCloseEvent *event) override; void paintEvent(QPaintEvent *event) override; bool event(QEvent *event) override; - void initStyleOption(QStyleOptionDockWidget *option) const; + virtual void initStyleOption(QStyleOptionDockWidget *option) const; private: Q_DECLARE_PRIVATE(QDockWidget) diff --git a/src/widgets/widgets/qfocusframe.h b/src/widgets/widgets/qfocusframe.h index 73d5b42bd8..8f6b7dd067 100644 --- a/src/widgets/widgets/qfocusframe.h +++ b/src/widgets/widgets/qfocusframe.h @@ -64,7 +64,7 @@ protected: bool eventFilter(QObject *, QEvent *) override; void paintEvent(QPaintEvent *) override; - void initStyleOption(QStyleOption *option) const; + virtual void initStyleOption(QStyleOption *option) const; private: Q_DECLARE_PRIVATE(QFocusFrame) diff --git a/src/widgets/widgets/qframe.h b/src/widgets/widgets/qframe.h index 595dfa929d..144003bc0e 100644 --- a/src/widgets/widgets/qframe.h +++ b/src/widgets/widgets/qframe.h @@ -116,7 +116,7 @@ protected: protected: QFrame(QFramePrivate &dd, QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); - void initStyleOption(QStyleOptionFrame *option) const; + virtual void initStyleOption(QStyleOptionFrame *option) const; private: Q_DISABLE_COPY(QFrame) diff --git a/src/widgets/widgets/qgroupbox.h b/src/widgets/widgets/qgroupbox.h index bd8394b43b..f3ed35b7fb 100644 --- a/src/widgets/widgets/qgroupbox.h +++ b/src/widgets/widgets/qgroupbox.h @@ -94,7 +94,7 @@ protected: void mousePressEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; - void initStyleOption(QStyleOptionGroupBox *option) const; + virtual void initStyleOption(QStyleOptionGroupBox *option) const; private: diff --git a/src/widgets/widgets/qlineedit.h b/src/widgets/widgets/qlineedit.h index 41efab9229..d47f979a63 100644 --- a/src/widgets/widgets/qlineedit.h +++ b/src/widgets/widgets/qlineedit.h @@ -229,7 +229,7 @@ protected: #endif void inputMethodEvent(QInputMethodEvent *) override; - void initStyleOption(QStyleOptionFrame *option) const; + virtual void initStyleOption(QStyleOptionFrame *option) const; public: QVariant inputMethodQuery(Qt::InputMethodQuery) const override; Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const; diff --git a/src/widgets/widgets/qmenu.h b/src/widgets/widgets/qmenu.h index b770b27957..e8b27c3278 100644 --- a/src/widgets/widgets/qmenu.h +++ b/src/widgets/widgets/qmenu.h @@ -257,7 +257,7 @@ protected: void timerEvent(QTimerEvent *) override; bool event(QEvent *) override; bool focusNextPrevChild(bool next) override; - void initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const; + virtual void initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const; private Q_SLOTS: void internalDelayedPopup(); diff --git a/src/widgets/widgets/qmenubar.h b/src/widgets/widgets/qmenubar.h index cf6663f94a..f2170ebf5a 100644 --- a/src/widgets/widgets/qmenubar.h +++ b/src/widgets/widgets/qmenubar.h @@ -150,7 +150,7 @@ protected: void timerEvent(QTimerEvent *) override; bool eventFilter(QObject *, QEvent *) override; bool event(QEvent *) override; - void initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const; + virtual void initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const; private: Q_DECLARE_PRIVATE(QMenuBar) diff --git a/src/widgets/widgets/qprogressbar.cpp b/src/widgets/widgets/qprogressbar.cpp index 04241fda09..f94cbd3172 100644 --- a/src/widgets/widgets/qprogressbar.cpp +++ b/src/widgets/widgets/qprogressbar.cpp @@ -107,6 +107,8 @@ void QProgressBarPrivate::resetLayoutItemMargins() { Q_Q(QProgressBar); QStyleOptionProgressBar option; + // ### It seems like this can be called directly from the constructor which should be avoided + // ### if possible, since we will not call a possible re-implemented version q->initStyleOption(&option); setLayoutItemMargins(QStyle::SE_ProgressBarLayoutItem, &option); } diff --git a/src/widgets/widgets/qprogressbar.h b/src/widgets/widgets/qprogressbar.h index ec9686068c..e112af416b 100644 --- a/src/widgets/widgets/qprogressbar.h +++ b/src/widgets/widgets/qprogressbar.h @@ -111,7 +111,7 @@ Q_SIGNALS: protected: bool event(QEvent *e) override; void paintEvent(QPaintEvent *) override; - void initStyleOption(QStyleOptionProgressBar *option) const; + virtual void initStyleOption(QStyleOptionProgressBar *option) const; private: Q_DECLARE_PRIVATE(QProgressBar) diff --git a/src/widgets/widgets/qpushbutton.h b/src/widgets/widgets/qpushbutton.h index 283dfe2c61..5452f4227b 100644 --- a/src/widgets/widgets/qpushbutton.h +++ b/src/widgets/widgets/qpushbutton.h @@ -93,7 +93,7 @@ protected: void keyPressEvent(QKeyEvent *) override; void focusInEvent(QFocusEvent *) override; void focusOutEvent(QFocusEvent *) override; - void initStyleOption(QStyleOptionButton *option) const; + virtual void initStyleOption(QStyleOptionButton *option) const; bool hitButton(const QPoint &pos) const override; QPushButton(QPushButtonPrivate &dd, QWidget* parent = nullptr); diff --git a/src/widgets/widgets/qradiobutton.h b/src/widgets/widgets/qradiobutton.h index c6b5ddce84..009e7107c6 100644 --- a/src/widgets/widgets/qradiobutton.h +++ b/src/widgets/widgets/qradiobutton.h @@ -68,7 +68,7 @@ protected: bool hitButton(const QPoint &) const override; void paintEvent(QPaintEvent *) override; void mouseMoveEvent(QMouseEvent *) override; - void initStyleOption(QStyleOptionButton *button) const; + virtual void initStyleOption(QStyleOptionButton *button) const; private: diff --git a/src/widgets/widgets/qrubberband.h b/src/widgets/widgets/qrubberband.h index c683c24a18..9822f036f1 100644 --- a/src/widgets/widgets/qrubberband.h +++ b/src/widgets/widgets/qrubberband.h @@ -79,7 +79,7 @@ protected: void showEvent(QShowEvent *) override; void resizeEvent(QResizeEvent *) override; void moveEvent(QMoveEvent *) override; - void initStyleOption(QStyleOptionRubberBand *option) const; + virtual void initStyleOption(QStyleOptionRubberBand *option) const; private: Q_DECLARE_PRIVATE(QRubberBand) diff --git a/src/widgets/widgets/qscrollbar.h b/src/widgets/widgets/qscrollbar.h index 171195fd24..de4e0c14c7 100644 --- a/src/widgets/widgets/qscrollbar.h +++ b/src/widgets/widgets/qscrollbar.h @@ -76,7 +76,7 @@ protected: #ifndef QT_NO_CONTEXTMENU void contextMenuEvent(QContextMenuEvent *) override; #endif - void initStyleOption(QStyleOptionSlider *option) const; + virtual void initStyleOption(QStyleOptionSlider *option) const; private: diff --git a/src/widgets/widgets/qslider.cpp b/src/widgets/widgets/qslider.cpp index c344d496a7..5accb9c92f 100644 --- a/src/widgets/widgets/qslider.cpp +++ b/src/widgets/widgets/qslider.cpp @@ -91,6 +91,8 @@ void QSliderPrivate::resetLayoutItemMargins() { Q_Q(QSlider); QStyleOptionSlider opt; + // ### This is (also) reached from the ctor which is unfortunate since a possible + // ### re-implementation of initStyleOption is then not called. q->initStyleOption(&opt); setLayoutItemMargins(QStyle::SE_SliderLayoutItem, &opt); } diff --git a/src/widgets/widgets/qslider.h b/src/widgets/widgets/qslider.h index f74f9c8576..a4f05c3c12 100644 --- a/src/widgets/widgets/qslider.h +++ b/src/widgets/widgets/qslider.h @@ -89,7 +89,7 @@ protected: void mousePressEvent(QMouseEvent *ev) override; void mouseReleaseEvent(QMouseEvent *ev) override; void mouseMoveEvent(QMouseEvent *ev) override; - void initStyleOption(QStyleOptionSlider *option) const; + virtual void initStyleOption(QStyleOptionSlider *option) const; private: diff --git a/src/widgets/widgets/qtabbar.h b/src/widgets/widgets/qtabbar.h index cf98834853..7feea6d2a0 100644 --- a/src/widgets/widgets/qtabbar.h +++ b/src/widgets/widgets/qtabbar.h @@ -212,7 +212,7 @@ protected: void keyPressEvent(QKeyEvent *) override; void changeEvent(QEvent *) override; void timerEvent(QTimerEvent *event) override; - void initStyleOption(QStyleOptionTab *option, int tabIndex) const; + virtual void initStyleOption(QStyleOptionTab *option, int tabIndex) const; #ifndef QT_NO_ACCESSIBILITY friend class QAccessibleTabBar; diff --git a/src/widgets/widgets/qtabwidget.h b/src/widgets/widgets/qtabwidget.h index b61a02bdc6..0b91f077e0 100644 --- a/src/widgets/widgets/qtabwidget.h +++ b/src/widgets/widgets/qtabwidget.h @@ -171,7 +171,7 @@ protected: void setTabBar(QTabBar *); void changeEvent(QEvent *) override; bool event(QEvent *) override; - void initStyleOption(QStyleOptionTabWidgetFrame *option) const; + virtual void initStyleOption(QStyleOptionTabWidgetFrame *option) const; private: diff --git a/src/widgets/widgets/qtoolbar.h b/src/widgets/widgets/qtoolbar.h index 220b30abbe..26cad77b64 100644 --- a/src/widgets/widgets/qtoolbar.h +++ b/src/widgets/widgets/qtoolbar.h @@ -181,7 +181,7 @@ protected: void changeEvent(QEvent *event) override; void paintEvent(QPaintEvent *event) override; bool event(QEvent *event) override; - void initStyleOption(QStyleOptionToolBar *option) const; + virtual void initStyleOption(QStyleOptionToolBar *option) const; private: diff --git a/src/widgets/widgets/qtoolbutton.h b/src/widgets/widgets/qtoolbutton.h index 52bd2d5f7a..5d522c62bb 100644 --- a/src/widgets/widgets/qtoolbutton.h +++ b/src/widgets/widgets/qtoolbutton.h @@ -119,7 +119,7 @@ protected: bool hitButton(const QPoint &pos) const override; void nextCheckState() override; - void initStyleOption(QStyleOptionToolButton *option) const; + virtual void initStyleOption(QStyleOptionToolButton *option) const; private: Q_DISABLE_COPY(QToolButton)