I m using Qt 4.6.2 on windows xp
I need to draw horizontal ,vertical lines and an arc over the image .
My code isQt Code:To copy to clipboard, switch view to plain text mode
But only image is displayed ,no line is drawn....
I m using Qt 4.6.2 on windows xp
I need to draw horizontal ,vertical lines and an arc over the image .
My code isQt Code:To copy to clipboard, switch view to plain text mode
But only image is displayed ,no line is drawn....
you can only draw in a paintEvent().
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
You just need to setup your pixmap before you assign the painter:
Qt Code:To copy to clipboard, switch view to plain text mode
Joh
@Joh,
did you try the code you posted?
This code should not work.
At the very least in runtime a Qt warning should be printed, saying that QPainter can not be used outside the paintEvent().
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Sure I tried it! That's why I posted it as a complete application.
It doesn't show any warnings on the console, either. Why should it not be possible to use a QPainter on an 'offline' QPixMap?
Joh
you are right, QPixmap is not a widget.
Sorry.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Aah! Allright! That was the source of the confusion!
Yes, and not beeing able to draw onto a widget outside the paintEvent makes perfect sense.
Hope we didn't confuse the OP :->
Joh
I m still not able to draw line on image
My code is
Qt Code:
QPixmap pixmap; ui->lbl_plane->resize(pixmap.size()); painter.setPen(GreenPen); painter.drawLine(250,300,500,300); ui->lbl_plane->setPixmap(pixmap); ui->lbl_plane->show();To copy to clipboard, switch view to plain text mode
The image format is "Format_RGB32"
what I m missing?
give your pixmap a size.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
I have added line which is my image size to above code but still no line is drawn on image....
try adding painter.end() after the drawLine().
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Try the following code.
Its works I tested it.
Once it works for you see what it is you are doing wrong:
Qt Code:
int main(int argc, char *argv[]) { QLabel l; painter.setPen(Red); painter.drawLine(50,50,250,250); l.setPixmap(pixmap); l.show(); return a.exec(); }To copy to clipboard, switch view to plain text mode
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Bookmarks