ListView Custom delegate crash in paint
-
Hi,
I have created my Listview with custom Delegate. The paint method looks like this:
@void List_view_delegate::paint(QPainter * painter, const QStyleOptionViewItem & option,
const QModelIndex & index) const
{
m_item_widget->resize(option.rect.size());// Update data of widget here.
const QString name = index.data(Character_model::CharacterNameRole).toString();
m_item_widget->set_name(name);QPalette pal;
pal.setBrush(QPalette::Window, QBrush(QColor(Qt::transparent)));m_item_widget->setPalette(pal);
// Paint the widget now.
painter->save();
painter->translate(option.rect.topLeft());
m_item_widget->render(painter);
painter->restore();
}@This List_view is a part of a Widget which has a QPropertyAnimation set on its maximumWidth to give animated sliding of the widget. When the widget maximumWidth becomes 0, the paint() method of listview crashes in the render method.
SOmebody has a clue??
-
The output shows:
QPaintDevice: Cannot destroy paint device that is being painted
ASSERT: "enginePriv" in file kernel/qwidget.cpp, line 4725 -
Hi,
Silly question but why are you painting a widget which has no size ?
-
No I am not painting on no size.
The animation reduces the size but still paint event is called because animation is resizing the widget.
-
What if you stop at one and then make the widget invisible rather that go to zero ?
-
Actually I suspected that the widget is getting of size 0. I tried to print the option.rect.size() in paint() of my delegate and it prints:
QSize(790, 182)
QSize(790, 182)
QSize(790, 182)
QSize(596, 182)and after this it gives segmentation fault.
-
Strange part is that it asserts in Qt
engine->d_func()
That is where is asserting. I dont understand
-
Can you show a complete stack trace ?
-
I hope this helps:
-
What is Characters_view_delegate ?
-
Characters_view_delegate is my custom delegate for my QListView. I paint my delegate in paint. In the above code ,
List_view_delegate = Characters_view_delegate -
Can you create a minimal example that shows the crash ?