From c501e09efacb8a60deb41f85f3402f6f4c041d95 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Sun, 16 Aug 2020 13:55:11 +0200 Subject: Replace QAbstractItemView::viewOptions with initViewItemOption viewOptions returned a QStyleOptionViewItem object. Such a method can never support newer versions of the option structure. Most styleable QWidget classes provide a virtual method initStyleOption that initializes the option object passed in as a pointer, e.g QFrame, QAbstractSpinBox, or QComboBox. Follow that API convention, but name it initViewItemOption, as the QStyleOptionViewItem struct contains information about the item as well as the widget itelf. This is a source incompatible change that will go unnoticed unless existing subclasses mark their overrides as 'override', or call the removed QAbstractItemView::viewOption virtual function. [ChangeLog][QtWidgets][QAbstractItemView] The virtual viewOptions method that previously returned a QStyleOptionViewItem object has been renamed to initViewItemOption, and initializes a QStyleOptionViewItem object that's passed in through a pointer. Change-Id: Ie058702aed42d77274fa3c4abb43ba302e57e348 Reviewed-by: Richard Moe Gustavsen --- examples/widgets/itemviews/chart/pieview.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'examples/widgets/itemviews/chart/pieview.cpp') diff --git a/examples/widgets/itemviews/chart/pieview.cpp b/examples/widgets/itemviews/chart/pieview.cpp index af77970633..8ebe6a9d89 100644 --- a/examples/widgets/itemviews/chart/pieview.cpp +++ b/examples/widgets/itemviews/chart/pieview.cpp @@ -137,7 +137,9 @@ QModelIndex PieView::indexAt(const QPoint &point) const } } } else { - double itemHeight = QFontMetrics(viewOptions().font).height(); + QStyleOptionViewItem option; + initViewItemOption(&option); + double itemHeight = QFontMetrics(option.font).height(); int listItem = int((wy - margin) / itemHeight); int validRow = 0; @@ -193,8 +195,9 @@ QRect PieView::itemRect(const QModelIndex &index) const switch (index.column()) { case 0: { - const qreal itemHeight = QFontMetricsF(viewOptions().font).height(); - + QStyleOptionViewItem option; + initViewItemOption(&option); + const qreal itemHeight = QFontMetricsF(option.font).height(); return QRect(totalSize, qRound(margin + listItem * itemHeight), totalSize - margin, qRound(itemHeight)); @@ -306,7 +309,8 @@ QModelIndex PieView::moveCursor(QAbstractItemView::CursorAction cursorAction, void PieView::paintEvent(QPaintEvent *event) { QItemSelectionModel *selections = selectionModel(); - QStyleOptionViewItem option = viewOptions(); + QStyleOptionViewItem option; + initViewItemOption(&option); QBrush background = option.palette.base(); QPen foreground(option.palette.color(QPalette::WindowText)); @@ -363,7 +367,9 @@ void PieView::paintEvent(QPaintEvent *event) if (value > 0.0) { QModelIndex labelIndex = model()->index(row, 0, rootIndex()); - QStyleOptionViewItem option = viewOptions(); + QStyleOptionViewItem option; + initViewItemOption(&option); + option.rect = visualRect(labelIndex); if (selections->isSelected(labelIndex)) option.state |= QStyle::State_Selected; -- cgit v1.2.3