Workaround Qt bug in Windows 11 style
Pass a widget when invoking `QStyle::drawControl()`; the Windows 11 style uses the widget unconditionally. Considering the documentation explicitly states `The widget argument is optional` and the default value for the function argument is `nullptr` this is supposedly a bug in Qt.
This commit is contained in:
parent
96f26e8f37
commit
15b60102a1
|
@ -38,7 +38,7 @@ void DevButtonsItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
||||||
initStyleOption(&opt, index);
|
initStyleOption(&opt, index);
|
||||||
opt.text.clear();
|
opt.text.clear();
|
||||||
opt.features = QStyleOptionViewItem::None;
|
opt.features = QStyleOptionViewItem::None;
|
||||||
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter);
|
drawBasicItemViewItem(*painter, opt);
|
||||||
|
|
||||||
// draw text
|
// draw text
|
||||||
QRectF textRect = option.rect;
|
QRectF textRect = option.rect;
|
||||||
|
|
|
@ -33,11 +33,11 @@ void DirButtonsItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
||||||
QStyledItemDelegate::paint(painter, option, index);
|
QStyledItemDelegate::paint(painter, option, index);
|
||||||
} else {
|
} else {
|
||||||
// init style options to use drawControl(), except for the text
|
// init style options to use drawControl(), except for the text
|
||||||
QStyleOptionViewItem opt = option;
|
auto opt = option;
|
||||||
initStyleOption(&opt, index);
|
initStyleOption(&opt, index);
|
||||||
opt.text.clear();
|
opt.text.clear();
|
||||||
opt.features = QStyleOptionViewItem::None;
|
opt.features = QStyleOptionViewItem::None;
|
||||||
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter);
|
drawBasicItemViewItem(*painter, opt);
|
||||||
|
|
||||||
// draw text
|
// draw text
|
||||||
auto textRect = QRectF(option.rect);
|
auto textRect = QRectF(option.rect);
|
||||||
|
|
|
@ -45,7 +45,7 @@ void DownloadItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
||||||
} else {
|
} else {
|
||||||
opt.text = option.fontMetrics.elidedText(opt.text, Qt::ElideMiddle, opt.rect.width() / 2 - 4);
|
opt.text = option.fontMetrics.elidedText(opt.text, Qt::ElideMiddle, opt.rect.width() / 2 - 4);
|
||||||
}
|
}
|
||||||
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter);
|
drawBasicItemViewItem(*painter, opt);
|
||||||
|
|
||||||
// draw progress bar
|
// draw progress bar
|
||||||
const QAbstractItemModel *model = index.model();
|
const QAbstractItemModel *model = index.model();
|
||||||
|
|
|
@ -3,8 +3,11 @@
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) && QT_VERSION < QT_VERSION_CHECK(6, 3, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) && QT_VERSION < QT_VERSION_CHECK(6, 3, 0)
|
||||||
#include <QLibraryInfo>
|
#include <QLibraryInfo>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
|
#include <QStyleOptionViewItem>
|
||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
|
|
||||||
namespace QtGui {
|
namespace QtGui {
|
||||||
|
@ -30,4 +33,11 @@ void showViewMenu(const QPoint &position, const QTreeView &view, QMenu &menu)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void drawBasicItemViewItem(QPainter &painter, const QStyleOptionViewItem &option)
|
||||||
|
{
|
||||||
|
if (auto *const style = option.widget ? option.widget->style() : QApplication::style()) {
|
||||||
|
style->drawControl(QStyle::CE_ItemViewItem, &option, &painter, option.widget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace QtGui
|
} // namespace QtGui
|
||||||
|
|
|
@ -12,12 +12,15 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
|
QT_FORWARD_DECLARE_CLASS(QPainter)
|
||||||
QT_FORWARD_DECLARE_CLASS(QPoint)
|
QT_FORWARD_DECLARE_CLASS(QPoint)
|
||||||
QT_FORWARD_DECLARE_CLASS(QMenu)
|
QT_FORWARD_DECLARE_CLASS(QMenu)
|
||||||
|
QT_FORWARD_DECLARE_CLASS(QStyleOptionViewItem)
|
||||||
|
|
||||||
namespace QtGui {
|
namespace QtGui {
|
||||||
|
|
||||||
void showViewMenu(const QPoint &position, const QTreeView &view, QMenu &menu);
|
void showViewMenu(const QPoint &position, const QTreeView &view, QMenu &menu);
|
||||||
|
void drawBasicItemViewItem(QPainter &painter, const QStyleOptionViewItem &option);
|
||||||
|
|
||||||
inline auto copyToClipboard(const QString &text)
|
inline auto copyToClipboard(const QString &text)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue