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);
|
||||
opt.text.clear();
|
||||
opt.features = QStyleOptionViewItem::None;
|
||||
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter);
|
||||
drawBasicItemViewItem(*painter, opt);
|
||||
|
||||
// draw text
|
||||
QRectF textRect = option.rect;
|
||||
|
|
|
@ -33,11 +33,11 @@ void DirButtonsItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
|||
QStyledItemDelegate::paint(painter, option, index);
|
||||
} else {
|
||||
// init style options to use drawControl(), except for the text
|
||||
QStyleOptionViewItem opt = option;
|
||||
auto opt = option;
|
||||
initStyleOption(&opt, index);
|
||||
opt.text.clear();
|
||||
opt.features = QStyleOptionViewItem::None;
|
||||
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter);
|
||||
drawBasicItemViewItem(*painter, opt);
|
||||
|
||||
// draw text
|
||||
auto textRect = QRectF(option.rect);
|
||||
|
|
|
@ -45,7 +45,7 @@ void DownloadItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
|||
} else {
|
||||
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
|
||||
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)
|
||||
#include <QLibraryInfo>
|
||||
#endif
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMenu>
|
||||
#include <QPoint>
|
||||
#include <QStyleOptionViewItem>
|
||||
#include <QTreeView>
|
||||
|
||||
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
|
||||
|
|
|
@ -12,12 +12,15 @@
|
|||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QPainter)
|
||||
QT_FORWARD_DECLARE_CLASS(QPoint)
|
||||
QT_FORWARD_DECLARE_CLASS(QMenu)
|
||||
QT_FORWARD_DECLARE_CLASS(QStyleOptionViewItem)
|
||||
|
||||
namespace QtGui {
|
||||
|
||||
void showViewMenu(const QPoint &position, const QTreeView &view, QMenu &menu);
|
||||
void drawBasicItemViewItem(QPainter &painter, const QStyleOptionViewItem &option);
|
||||
|
||||
inline auto copyToClipboard(const QString &text)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue