[Qt-interest] Drawing rectangular
Samuel Rødal
sroedal at trolltech.com
Mon Sep 21 12:47:27 CEST 2009
Yuvaraj R wrote:
> still i am not getting
>
> i am getting following things in log
>
>
> QPainter::begin: Paint device returned engine == 0, type: 1
>
> QPainter::drawRects: Painter not active
>
> QPainter::end: Painter not active, aborted
>
> QPainter::setPen: Painter not active
>
> QPainter::drawRects: Painter not active
>
>
> Thanks
>
>
> Yuvaraj R
>
> To call the base class paint event, your text browser class' paint
> event should look like this:
>
>
> void text_browser::paintEvent(QPaintEvent *e)
> {
> QTextBrowser::paintEvent(e);
> QPainter painter;
> painter.setPen(Qt::red);
> painter.drawRect(100,100,100,100);
> }
>
> I don't think calling accept() makes any difference for paint events.
>
> --
> Samuel
>
Right, that should have been QPainter painter(this); and not just
QPainter painter;
But another problem is that QTextBrowser is an abstract scroll area,
which means that its paint event actually paints into the viewport
widget, not into the widget itself.
Try "QPainter painter(viewport());" instead.
Refer to http://doc.trolltech.com/4.5/qabstractscrollarea.html#details
for more information on QAbstractScrollArea.
--
Samuel
More information about the Qt-interest-old
mailing list