PDA

View Full Version : how to draw a rectangle on an image label without overloading paintEvent function



qt_user
26th August 2010, 20:34
i want to draw a rectangle on an image label without overloading paintEvent function......... I don't want to use paintEvent b'coz i have to pas the name of the image to be displayed(frameName) each time I display an image out of a series of images.
Earlier I had drawn suing the following code in the paintEvent function.Now how should I do it without using the paintEvent function.



if((i >= startFrameMarkerPosition)&&(i < endFrameMarkerPosition))
{
painter.drawPixmap(0,0,QPixmap(localFileName.at(i) ));

int x,y,w,h;
x=100; y=200; w=TIME_INTERVAL_PROCESSING_PLAY;h=60;
painter.setPen(Qt::red);
painter.drawRect(x,y,w,h);

QLabel::paintEvent(event);

localSlider->setValue(i);
i++;
}


Thanx in advance!!

Lykurg
26th August 2010, 20:39
You can use QPainter also direct on the image. So draw on the image and set it to your label.

qt_user
27th August 2010, 05:40
I have implemented it as:



if((i >= startFrameMarkerPosition)&&(i < endFrameMarkerPosition))
{
painter.drawPixmap(0,0,QPixmap(currentFrameName));//When this line //is commented,even then the rectangle drawn below is not displayed.Actually neither of them //is working(the 'drawPixmap' and the 'drawRect')

int x,y,w,h;
x=100; y=200; w=80;h=60;
painter.setPen(Qt::red);
painter.drawRect(x,y,w,h);

//QLabel::paintEvent(event);

localSlider->setValue(i);
i++;
}


Can you tell me how to draw on an image!

tbscope
27th August 2010, 06:00
Something in the lines of:


QPixmap myPixmap(100, 100); // size
QPainter painter(&myPixmap);

// Use the painter to draw things

// Then use the pixmap like:
myLabel->setPixmap(myPixmap);