mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-12 12:54:29 +00:00
KItemListWidget: Use initStyleOption
Instead of using QStyleOption::initFrom, let's use QGraphicsWidget::initStyleOption, which is made for exactly the purpose of KItemListWidget. This is especially important since, according to the docs of QGraphicsItem::paint "The widget argument is optional. [...] For cached painting, widget is always 0.". Even though currently no code in dolphin does cached painting, for the sake of modularity one should not rely on widget to be non-null. Using QStyleOption::initFrom does assume that, though. In fact, GammaRay asks the items to do cached painting when attaching it to the application, causing it to crash.
This commit is contained in:
parent
6100f66ae2
commit
037d2c9984
|
@ -670,7 +670,7 @@ void KItemListView::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt
|
|||
}
|
||||
|
||||
QStyleOptionRubberBand opt;
|
||||
opt.initFrom(widget);
|
||||
initStyleOption(&opt);
|
||||
opt.shape = QRubberBand::Rectangle;
|
||||
opt.opaque = false;
|
||||
opt.rect = rubberBandRect.toRect();
|
||||
|
|
|
@ -127,7 +127,7 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
|
|||
|
||||
if (m_current && m_editedRole.isEmpty()) {
|
||||
QStyleOptionFocusRect focusRectOption;
|
||||
focusRectOption.initFrom(widget);
|
||||
initStyleOption(&focusRectOption);
|
||||
focusRectOption.rect = textFocusRect().toRect();
|
||||
focusRectOption.state = QStyle::State_Enabled | QStyle::State_Item | QStyle::State_KeyboardFocusChange;
|
||||
if (m_selected) {
|
||||
|
@ -517,11 +517,11 @@ void KItemListWidget::clearHoverCache()
|
|||
void KItemListWidget::drawItemStyleOption(QPainter* painter, QWidget* widget, QStyle::State styleState)
|
||||
{
|
||||
QStyleOptionViewItem viewItemOption;
|
||||
viewItemOption.initFrom(widget);
|
||||
initStyleOption(&viewItemOption);
|
||||
viewItemOption.state = styleState;
|
||||
viewItemOption.viewItemPosition = QStyleOptionViewItem::OnlyOne;
|
||||
viewItemOption.showDecorationSelected = true;
|
||||
viewItemOption.rect = selectionRect().toRect();
|
||||
widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget);
|
||||
style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue