Solved QListWidget::setItemWidget() with scrollbar crashes?
-
in the doc for
setItemWidget()
, it says:This function should only be used to display static content in the place of a list widget item. If you want to display custom dynamic content ..., use QListView
Q1: Why? There's no explanation for why we shouldn't do that.
Q2: Does "dynamic content" include a scroll bar?So I put a scroll bar set inside the list item widget (among other things like a couple labels and a stop sign), AND the entire panel can be moved around with a splitter that separates it from a QTableView. When i move the splitter around, the app will invariably crash with this:
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setCompositionMode: Painter not activenotes:
- no scroll bar no crash. ie: if there's no widget set, or if the widget is JUST a QLabel: no crash. ONLY when it is has a vanilla QScrollBar will it crash.
- doesn't crash if i don't move the splitter, but that defeats the purpose of having a splitter.
- doesn't crash if i use a generic QWidget and do all my own custom drawing to simulate the scroll bar, so we know it's directly related to QScrollBar. i want to use QScrollBar cuz it handles "indeterminate state" in a visually pleasing way
Here's what it looks like, for your visual pleasure:
-
i gave up attempting to use QProgressBar and just rolled my own derived from QWidget. works flawlessly.
-
Hi,
@davecotter said in QListWidget::setItemWidget() with scrollbar crashes?:
Q1: Why? There's no explanation for why we shouldn't do that.
Well, the warning explains that it's for displaying static content. For more details you can check the implementation.
@davecotter said in QListWidget::setItemWidget() with scrollbar crashes?:
Q2: Does "dynamic content" include a scroll bar?
IIRC, QScrollBar may be blinking.
-
@davecotter said in QListWidget::setItemWidget() with scrollbar crashes?:
Q1: Why? There's no explanation for why we shouldn't do that.
The rationale is that you shouldn't create a widget for each item. For a table that supports 1k items, that means creating 1k widgets even if they're never displayed/used. If you want custom behaviour the conventional wisdom is to use a
Q*View
and add a delegate to it. The latter being invoked whenever there's something be shown. -
i gave up attempting to use QProgressBar and just rolled my own derived from QWidget. works flawlessly.