Make initStyleOption virtual for various classes
Often a simple change in the styleoptions is needed in e.g a paintEvent, but it was impossible without copying the whole paint-function which is not always trivial and also wouldn't be kept up-to-date if it was changed in Qt. The initStyleOption is similar to viewOptions in QAbstractTableView and it is handy that this function is virtual. Furthermore QStyledItemDelegate::initStyleOption is already virtual. This change only makes initStyleOption virtual for public classes. [ChangeLog][QtWidgets] InitStyleOption has been made virtual in public Qt classes to make override of stylebehavior more simple. Change-Id: I38974c6d4dd0793ca5976ecf3aa28892215a1579 Task-number: QTBUG-77642 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
This commit is contained in:
parent
9c0f448f5a
commit
24d60cb64d
@ -3385,6 +3385,14 @@ void QHeaderView::initStyleOption(QStyleOptionHeader *option) const
|
|||||||
option->section = 0;
|
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
|
bool QHeaderViewPrivate::isSectionSelected(int section) const
|
||||||
{
|
{
|
||||||
int i = section * 2;
|
int i = section * 2;
|
||||||
|
@ -230,12 +230,14 @@ protected:
|
|||||||
QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers) override;
|
QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers) override;
|
||||||
void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags) override;
|
void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags) override;
|
||||||
QRegion visualRegionForSelection(const QItemSelection &selection) const override;
|
QRegion visualRegionForSelection(const QItemSelection &selection) const override;
|
||||||
void initStyleOption(QStyleOptionHeader *option) const;
|
virtual void initStyleOption(QStyleOptionHeader *option) const;
|
||||||
|
|
||||||
friend class QTableView;
|
friend class QTableView;
|
||||||
friend class QTreeView;
|
friend class QTreeView;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void initStyleOption(QStyleOptionFrame *option) const override;
|
||||||
|
|
||||||
// ### Qt6: make them protected slots in QHeaderViewPrivate
|
// ### 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_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))
|
Q_PRIVATE_SLOT(d_func(), void _q_sectionsAboutToBeMoved(const QModelIndex &sourceParent, int logicalStart, int logicalEnd, const QModelIndex &destinationParent, int logicalDestination))
|
||||||
|
@ -1629,6 +1629,8 @@ void QAbstractSpinBoxPrivate::init()
|
|||||||
edit->setValidator(validator);
|
edit->setValidator(validator);
|
||||||
|
|
||||||
QStyleOptionSpinBox opt;
|
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);
|
q->initStyleOption(&opt);
|
||||||
spinClickTimerInterval = q->style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatRate, &opt, q);
|
spinClickTimerInterval = q->style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatRate, &opt, q);
|
||||||
spinClickThresholdTimerInterval = q->style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatThreshold, &opt, q);
|
spinClickThresholdTimerInterval = q->style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatThreshold, &opt, q);
|
||||||
|
@ -160,7 +160,7 @@ protected:
|
|||||||
void timerEvent(QTimerEvent *event) override;
|
void timerEvent(QTimerEvent *event) override;
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
void showEvent(QShowEvent *event) override;
|
void showEvent(QShowEvent *event) override;
|
||||||
void initStyleOption(QStyleOptionSpinBox *option) const;
|
virtual void initStyleOption(QStyleOptionSpinBox *option) const;
|
||||||
|
|
||||||
QLineEdit *lineEdit() const;
|
QLineEdit *lineEdit() const;
|
||||||
void setLineEdit(QLineEdit *edit);
|
void setLineEdit(QLineEdit *edit);
|
||||||
|
@ -81,7 +81,7 @@ protected:
|
|||||||
void nextCheckState() override;
|
void nextCheckState() override;
|
||||||
void paintEvent(QPaintEvent *) override;
|
void paintEvent(QPaintEvent *) override;
|
||||||
void mouseMoveEvent(QMouseEvent *) override;
|
void mouseMoveEvent(QMouseEvent *) override;
|
||||||
void initStyleOption(QStyleOptionButton *option) const;
|
virtual void initStyleOption(QStyleOptionButton *option) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -230,7 +230,7 @@ protected:
|
|||||||
void contextMenuEvent(QContextMenuEvent *e) override;
|
void contextMenuEvent(QContextMenuEvent *e) override;
|
||||||
#endif // QT_NO_CONTEXTMENU
|
#endif // QT_NO_CONTEXTMENU
|
||||||
void inputMethodEvent(QInputMethodEvent *) override;
|
void inputMethodEvent(QInputMethodEvent *) override;
|
||||||
void initStyleOption(QStyleOptionComboBox *option) const;
|
virtual void initStyleOption(QStyleOptionComboBox *option) const;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -193,7 +193,7 @@ protected:
|
|||||||
StepEnabled stepEnabled() const override;
|
StepEnabled stepEnabled() const override;
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
void paintEvent(QPaintEvent *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);
|
QDateTimeEdit(const QVariant &val, QMetaType::Type parserType, QWidget *parent = nullptr);
|
||||||
private:
|
private:
|
||||||
|
@ -90,7 +90,7 @@ protected:
|
|||||||
void mouseMoveEvent(QMouseEvent *me) override;
|
void mouseMoveEvent(QMouseEvent *me) override;
|
||||||
|
|
||||||
void sliderChange(SliderChange change) override;
|
void sliderChange(SliderChange change) override;
|
||||||
void initStyleOption(QStyleOptionSlider *option) const;
|
virtual void initStyleOption(QStyleOptionSlider *option) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -116,7 +116,7 @@ protected:
|
|||||||
void closeEvent(QCloseEvent *event) override;
|
void closeEvent(QCloseEvent *event) override;
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
bool event(QEvent *event) override;
|
bool event(QEvent *event) override;
|
||||||
void initStyleOption(QStyleOptionDockWidget *option) const;
|
virtual void initStyleOption(QStyleOptionDockWidget *option) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DECLARE_PRIVATE(QDockWidget)
|
Q_DECLARE_PRIVATE(QDockWidget)
|
||||||
|
@ -64,7 +64,7 @@ protected:
|
|||||||
|
|
||||||
bool eventFilter(QObject *, QEvent *) override;
|
bool eventFilter(QObject *, QEvent *) override;
|
||||||
void paintEvent(QPaintEvent *) override;
|
void paintEvent(QPaintEvent *) override;
|
||||||
void initStyleOption(QStyleOption *option) const;
|
virtual void initStyleOption(QStyleOption *option) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DECLARE_PRIVATE(QFocusFrame)
|
Q_DECLARE_PRIVATE(QFocusFrame)
|
||||||
|
@ -116,7 +116,7 @@ protected:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
QFrame(QFramePrivate &dd, QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
QFrame(QFramePrivate &dd, QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||||
void initStyleOption(QStyleOptionFrame *option) const;
|
virtual void initStyleOption(QStyleOptionFrame *option) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(QFrame)
|
Q_DISABLE_COPY(QFrame)
|
||||||
|
@ -94,7 +94,7 @@ protected:
|
|||||||
void mousePressEvent(QMouseEvent *event) override;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
void mouseMoveEvent(QMouseEvent *event) override;
|
void mouseMoveEvent(QMouseEvent *event) override;
|
||||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||||
void initStyleOption(QStyleOptionGroupBox *option) const;
|
virtual void initStyleOption(QStyleOptionGroupBox *option) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -229,7 +229,7 @@ protected:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void inputMethodEvent(QInputMethodEvent *) override;
|
void inputMethodEvent(QInputMethodEvent *) override;
|
||||||
void initStyleOption(QStyleOptionFrame *option) const;
|
virtual void initStyleOption(QStyleOptionFrame *option) const;
|
||||||
public:
|
public:
|
||||||
QVariant inputMethodQuery(Qt::InputMethodQuery) const override;
|
QVariant inputMethodQuery(Qt::InputMethodQuery) const override;
|
||||||
Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const;
|
Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const;
|
||||||
|
@ -257,7 +257,7 @@ protected:
|
|||||||
void timerEvent(QTimerEvent *) override;
|
void timerEvent(QTimerEvent *) override;
|
||||||
bool event(QEvent *) override;
|
bool event(QEvent *) override;
|
||||||
bool focusNextPrevChild(bool next) 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:
|
private Q_SLOTS:
|
||||||
void internalDelayedPopup();
|
void internalDelayedPopup();
|
||||||
|
@ -150,7 +150,7 @@ protected:
|
|||||||
void timerEvent(QTimerEvent *) override;
|
void timerEvent(QTimerEvent *) override;
|
||||||
bool eventFilter(QObject *, QEvent *) override;
|
bool eventFilter(QObject *, QEvent *) override;
|
||||||
bool event(QEvent *) override;
|
bool event(QEvent *) override;
|
||||||
void initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const;
|
virtual void initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DECLARE_PRIVATE(QMenuBar)
|
Q_DECLARE_PRIVATE(QMenuBar)
|
||||||
|
@ -107,6 +107,8 @@ void QProgressBarPrivate::resetLayoutItemMargins()
|
|||||||
{
|
{
|
||||||
Q_Q(QProgressBar);
|
Q_Q(QProgressBar);
|
||||||
QStyleOptionProgressBar option;
|
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);
|
q->initStyleOption(&option);
|
||||||
setLayoutItemMargins(QStyle::SE_ProgressBarLayoutItem, &option);
|
setLayoutItemMargins(QStyle::SE_ProgressBarLayoutItem, &option);
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ Q_SIGNALS:
|
|||||||
protected:
|
protected:
|
||||||
bool event(QEvent *e) override;
|
bool event(QEvent *e) override;
|
||||||
void paintEvent(QPaintEvent *) override;
|
void paintEvent(QPaintEvent *) override;
|
||||||
void initStyleOption(QStyleOptionProgressBar *option) const;
|
virtual void initStyleOption(QStyleOptionProgressBar *option) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DECLARE_PRIVATE(QProgressBar)
|
Q_DECLARE_PRIVATE(QProgressBar)
|
||||||
|
@ -93,7 +93,7 @@ protected:
|
|||||||
void keyPressEvent(QKeyEvent *) override;
|
void keyPressEvent(QKeyEvent *) override;
|
||||||
void focusInEvent(QFocusEvent *) override;
|
void focusInEvent(QFocusEvent *) override;
|
||||||
void focusOutEvent(QFocusEvent *) override;
|
void focusOutEvent(QFocusEvent *) override;
|
||||||
void initStyleOption(QStyleOptionButton *option) const;
|
virtual void initStyleOption(QStyleOptionButton *option) const;
|
||||||
bool hitButton(const QPoint &pos) const override;
|
bool hitButton(const QPoint &pos) const override;
|
||||||
QPushButton(QPushButtonPrivate &dd, QWidget* parent = nullptr);
|
QPushButton(QPushButtonPrivate &dd, QWidget* parent = nullptr);
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ protected:
|
|||||||
bool hitButton(const QPoint &) const override;
|
bool hitButton(const QPoint &) const override;
|
||||||
void paintEvent(QPaintEvent *) override;
|
void paintEvent(QPaintEvent *) override;
|
||||||
void mouseMoveEvent(QMouseEvent *) override;
|
void mouseMoveEvent(QMouseEvent *) override;
|
||||||
void initStyleOption(QStyleOptionButton *button) const;
|
virtual void initStyleOption(QStyleOptionButton *button) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -79,7 +79,7 @@ protected:
|
|||||||
void showEvent(QShowEvent *) override;
|
void showEvent(QShowEvent *) override;
|
||||||
void resizeEvent(QResizeEvent *) override;
|
void resizeEvent(QResizeEvent *) override;
|
||||||
void moveEvent(QMoveEvent *) override;
|
void moveEvent(QMoveEvent *) override;
|
||||||
void initStyleOption(QStyleOptionRubberBand *option) const;
|
virtual void initStyleOption(QStyleOptionRubberBand *option) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DECLARE_PRIVATE(QRubberBand)
|
Q_DECLARE_PRIVATE(QRubberBand)
|
||||||
|
@ -76,7 +76,7 @@ protected:
|
|||||||
#ifndef QT_NO_CONTEXTMENU
|
#ifndef QT_NO_CONTEXTMENU
|
||||||
void contextMenuEvent(QContextMenuEvent *) override;
|
void contextMenuEvent(QContextMenuEvent *) override;
|
||||||
#endif
|
#endif
|
||||||
void initStyleOption(QStyleOptionSlider *option) const;
|
virtual void initStyleOption(QStyleOptionSlider *option) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -91,6 +91,8 @@ void QSliderPrivate::resetLayoutItemMargins()
|
|||||||
{
|
{
|
||||||
Q_Q(QSlider);
|
Q_Q(QSlider);
|
||||||
QStyleOptionSlider opt;
|
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);
|
q->initStyleOption(&opt);
|
||||||
setLayoutItemMargins(QStyle::SE_SliderLayoutItem, &opt);
|
setLayoutItemMargins(QStyle::SE_SliderLayoutItem, &opt);
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ protected:
|
|||||||
void mousePressEvent(QMouseEvent *ev) override;
|
void mousePressEvent(QMouseEvent *ev) override;
|
||||||
void mouseReleaseEvent(QMouseEvent *ev) override;
|
void mouseReleaseEvent(QMouseEvent *ev) override;
|
||||||
void mouseMoveEvent(QMouseEvent *ev) override;
|
void mouseMoveEvent(QMouseEvent *ev) override;
|
||||||
void initStyleOption(QStyleOptionSlider *option) const;
|
virtual void initStyleOption(QStyleOptionSlider *option) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -212,7 +212,7 @@ protected:
|
|||||||
void keyPressEvent(QKeyEvent *) override;
|
void keyPressEvent(QKeyEvent *) override;
|
||||||
void changeEvent(QEvent *) override;
|
void changeEvent(QEvent *) override;
|
||||||
void timerEvent(QTimerEvent *event) 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
|
#ifndef QT_NO_ACCESSIBILITY
|
||||||
friend class QAccessibleTabBar;
|
friend class QAccessibleTabBar;
|
||||||
|
@ -171,7 +171,7 @@ protected:
|
|||||||
void setTabBar(QTabBar *);
|
void setTabBar(QTabBar *);
|
||||||
void changeEvent(QEvent *) override;
|
void changeEvent(QEvent *) override;
|
||||||
bool event(QEvent *) override;
|
bool event(QEvent *) override;
|
||||||
void initStyleOption(QStyleOptionTabWidgetFrame *option) const;
|
virtual void initStyleOption(QStyleOptionTabWidgetFrame *option) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -181,7 +181,7 @@ protected:
|
|||||||
void changeEvent(QEvent *event) override;
|
void changeEvent(QEvent *event) override;
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
bool event(QEvent *event) override;
|
bool event(QEvent *event) override;
|
||||||
void initStyleOption(QStyleOptionToolBar *option) const;
|
virtual void initStyleOption(QStyleOptionToolBar *option) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -119,7 +119,7 @@ protected:
|
|||||||
|
|
||||||
bool hitButton(const QPoint &pos) const override;
|
bool hitButton(const QPoint &pos) const override;
|
||||||
void nextCheckState() override;
|
void nextCheckState() override;
|
||||||
void initStyleOption(QStyleOptionToolButton *option) const;
|
virtual void initStyleOption(QStyleOptionToolButton *option) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(QToolButton)
|
Q_DISABLE_COPY(QToolButton)
|
||||||
|
Loading…
Reference in New Issue
Block a user