Problem with QListWidget and paintEvent()
I have inherited QListWidget and rewrote the paintEvent()-function as follows:
Code:
void InheritedListWidget
::paintEvent(QPaintEvent *event
) {
painter.
setRenderHint(QPainter::Antialiasing,
true);
};
painter.setBrush(Qt::black);
painter.drawPolygon(points, 3);
}
Now, for some reason when I'm running the program, nothing is painted on the list widget and the application prints to console:
Code:
QPainter::begin: Paint device returned engine
== 0, type
: 1 QPainter::setRenderHint: Painter must be active to set rendering hints
What is wrong with my code?
Re: Problem with QListWidget and paintEvent()
You should give viewport to QPainter.
See Qt docs:
Quote:
void QAbstractScrollArea:: paintEvent ( QPaintEvent * event ) [virtual protected]
This event handler can be reimplemented in a subclass to receive paint events (passed in event), for the viewport() widget.
Note: If you open a painter, make sure to open it on the viewport().
Re: Problem with QListWidget and paintEvent()
Thanks birchbay, this solved my problem!