View Full Version : DrawLine over QPixmap within Qlabel
Qt Coder
26th March 2009, 11:13
Hello all,
I Have one Qlabel in which I m displaying one .PNG image using QPixmap.
Now my program needs to draw few horizontal lines over this image..
How to add it?????
Lykurg
26th March 2009, 12:03
Hi, subclass QLabel and reimplemented QWidget::paintEvent ( QPaintEvent * event ). First pas the event to QLabel and then draw your lines using QPainter p(this);
Lykurg
EDIT: you also could modify your picture since QPixmap is a QPaintDevice. QPainter p(*yourPixmap);
spirit
26th March 2009, 12:07
or if you don't want to sublcass QLabel you can install event filter on your label and process QPainEvent.
Qt Coder
26th March 2009, 12:07
Hey could you please show me some code how to do this stuff??????
spirit
26th March 2009, 12:09
try this
QPixmap p;
QPainter painter(&p);
QLineF line(10.0, 80.0, 90.0, 20.0);
painter.drawLine(line);
label->setPixmap(p);
Lykurg
26th March 2009, 12:12
QPixmap pix(":/your/fancy/png/here");
QPainter p(&pix);
p->drawLine(pix.rect().topLeft(),pix.rect().bottomRig ht());
//use pix normaly...
Lykurg
26th March 2009, 12:13
Ok, I am out. spirit you get me one more time...:crying:
spirit
26th March 2009, 12:13
Ok, I am out. spirit you get me one more time...:crying:
sorry :rolleyes:
Qt Coder
26th March 2009, 12:21
Hey thanx both of you,
Its working now !!!!!!!!!!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.