Is there way to make a line in Label widget?
In my application, Label widget shows raw bitmap image from my device.
Then, I need to make a line in Label widget.
When I use drawLine() function (like shown blow), this line is made not in Label but main dialog
so I could not see the line because Label covers the line.
void MainWindow::paintEvent(QPaintEvent *)
if(image2.Buffer == NULL)
QPainter p; p.begin(this); QImage Image(800, 750, QImage::Format_ARGB32); loadImageData((uchar *)image2.Buffer, 750, 800, &Image); m_buffer = QPixmap::fromImage(Image); ui->ViewLable->setPixmap(m_buffer); p.drawLine(20,400,800,400); p.end(); Image.detach();
So, I would like to know the way to make a line on Label widget.
Subclass QLabel, and reimplement its paintEvent instead of the one of your main window. Then, you can simply overpaint the line directly on the widget, instead of on the image.
The problem with the code above, is that you create the painter on the this object: the MainWindow itself. If you wanted to paint on the image, you should have created it on the Image object. However, I don't get why you first create an image at all, only to convert it to a pixmap a few lines later.