[Qt-interest] Drawing rectangular

Samuel Rødal sroedal at trolltech.com
Mon Sep 21 09:37:21 CEST 2009


Yuvaraj R wrote:
> Hi All
> 
>  I am trying to draw rectangular in Main window, But i don't get my output..
> 
> My piece of code is:
> 
> QPainter *painter=new QPainter(this);
> 
> painter->setPen(Qt::red);
> 
> painter->drawRect(100,100,100,100);
> 
> 
> any mistake is there in above code ?

Is this code from the overriden paintEvent()? Make sure you delete the 
painter at the end, otherwise the painter will be left active on the 
widget after the paint event is done. Ideally you shouldn't even use new 
to create the painter, but create it on the stack.

--
Samuel



More information about the Qt-interest-old mailing list