Solved How to draw and change the region (semi-transparent) on top of a QLabel or QImage?
-
Do you see the image when you don't reimplement your paint event? I would guess no.
-
PaintWidget create QPixmap m_nPTargetPixmap and draws onm_nPTargetPixmap.
I set Qimage for Qlabel. Can I set Qpixmap on top of QImage in Qlabel and draw on Qpixmap? -
@Mikeeeeee
You can just move the line code to your MyLabel and draw directly there.
You dont need PaintWidget, it was just to show the logic of how to handle line drawing.However, i do wonder if you plan to be able to move the line after they are drawn or select them again ?
-
I would like to move the line along with QImage. But Qlabel is constantly changing its size. That's why I wanted to draw on the second layer.
-
In this example, how do you make it possible to draw lines instead of lines, as in Paint when you click curves?
-
@Mikeeeeee
Hi- In this example, how do you make it possible to draw lines instead of lines, as in Paint when you click curves?
im not sure what you ask?
When you click Curve in paint, you draw a curve, not a straight line.
(it looks like a Bezier Curve, but im not sure)Do you mean to draw a curve instead of a line?
You might be able to use
https://doc.qt.io/qt-5/qpainterpath.html#cubicTo
also some background
https://en.wikipedia.org/wiki/Bézier_curve#Higher-order_curves -
I need to like this example.
But there's a lot of code. Please help to highlight the desired code. -
@Mikeeeeee
What you show there seems to be just random paint. ( lots of points )
The sample you link seems to have some curve code
but the image you show as an example, its just drawn following the move and it is not a curve or line.So you want to make a free painting function?
-
Yes. Please help to finish this code.
-
@Mikeeeeee
well if you still using code from paintWidgetif(m_nbMousePressed)
{
painter.drawPixmap(0, 0, m_nPTargetPixmap);
painter.drawLine(m_line);
painter.drawPoint(m_line.p2() ); // paint the single point.
wasPressed = true;
}p2() is updated from
void PaintWidget::mouseMoveEvent(QMouseEvent *event) -
Did so, still draws a line.
void PaintWidget::paintEvent(QPaintEvent *e) { static bool wasPressed = false; QPainter painter(this); if(m_nbMousePressed) { //painter.drawPixmap(0, 0, m_nPTargetPixmap); //painter.drawLine(m_line); painter.drawPoint(m_line.p2() ); // paint the single point. wasPressed = true; } else if(wasPressed) { QPainter PixmapPainter(&m_nPTargetPixmap); QPen pen(Qt::green); PixmapPainter.setPen(pen); PixmapPainter.drawLine(m_line); painter.drawPixmap(0, 0, m_nPTargetPixmap); wasPressed = false; } }
Maybe you need to change:
PixmapPainter.drawLine(m_line);
-
Did so, also does not work
void PaintWidget::paintEvent(QPaintEvent *e) { static bool wasPressed = false; QPainter painter(this); if(m_nbMousePressed) { //painter.drawPixmap(0, 0, m_nPTargetPixmap); //painter.drawLine(m_line); painter.drawPoint(m_line.p2() ); // paint the single point. wasPressed = true; } else if(wasPressed) { QPainter PixmapPainter(&m_nPTargetPixmap); QPen pen(Qt::green); PixmapPainter.setPen(pen); //PixmapPainter.drawLine(m_line); PixmapPainter.drawPoint(m_line.p2()); painter.drawPixmap(0, 0, m_nPTargetPixmap); wasPressed = false; } }
-
ok. you have to debug it then :)
-
Found the solution here
-
But is it possible to set QLabel 2 QImages (one with image, the second transparent) and draw on transparent QImages?
-
No, you have to write it on your own by reimplementing the paintEvent()
-
I made this class Please tell me how to set the method set2Images()?
#ifndef QLABEL2IMAGES_H #define QLABEL2IMAGES_H #include "QLabel" class QLabel2Images : public QLabel { public: QLabel2Images(); ~QLabel2Images(); void set2Images(QImage &downImage, QImage &yopImage); }; #endif // QLABEL2IMAGES_H
-
@Mikeeeeee said in How to draw and change the region (semi-transparent) on top of a QLabel or QImage?:
how to set the method
Don't understand what you mean with this sentence - how to call this function? How to implement the function - since you're writing the function you should know it by your own.
-
I don't know how to implement it. Need one figure to place from below, the second figure(transparent) to place from above.
-
When the second image is (mostly) transparent then simply paint the first and then the second.