Unsolved How to draw over an old picture in QGraphicsScene
-
It turns out to draw in eventFilter, but it was necessary to add this line to the constructor.
myPixmap = QPixmap(myImageViewer->image.width(),myImageViewer->image.height());
I draw so:
bool MainWindow::eventFilter(QObject *obj, QEvent *event) { if(obj == myImageViewer and event->type() == QEvent::MouseButtonPress) { qDebug()<<" QEvent::MouseButtonPress"; QMouseEvent *mous = (QMouseEvent*)event; QPainter p(&myPixmap); p.setPen(myPen); p.drawPoint(mous->pos()); p.end(); lastPoint = mous->pos(); myImageViewer->imageLabel->setPixmap(myPixmap); } }
But when drawing the picture disappears and the screen turns black. How to fix? Can I set the drawing on the QImage overlay(":/Images/Images/mapTop.png");?
-
And if I do so, the screen becomes white.
myPixmap.fill();
How to make myPixmap transparent?
-
myPixmap.fill(Qt::transparent);
-
Thanks. Do so:
myPixmap = QPixmap(myImageViewer->image.width(),myImageViewer->image.height()); myPixmap.fill(Qt::transparent); myPixmap = QPixmap(":/Images/Images/mapTop.png");
But after drawing the picture disappears :
myImageViewer->setImage(mapImage);
How to get myPixmap the images:":/Images/Images/mapMain.png" and ":/Images/Images/mapTop.png" , but draw only on:
":/Images/Images/mapTop.png"? -
@Mikeeeeee
You mean draw myPixmap on mapImage and then
show the combined image with myImageViewer->setImage(mapImage); ?
Thats like before where we combined them. -
This post is deleted! -
Yes.The background will be mapImage, and I want to draw on it, with the ability to erase and make transparent Qpixmap. You may need to use: void QPixmap::setMask(const Bitmap &mask)
-
Tried to do so, but got an error: reference to type 'const QBitmap' could not bind to an lvalue of type 'QBitmap *'
QBitmap *myQBitmap = new QBitmap(); myQBitmap->fromImage(mapImage); myPixmap.setMask(myQBitmap);
-
@Mikeeeeee Please, read the documentation.
QBitmap::fromImage is a static method. You're using it wrong.
QPixmap::setMask takes a const reference to a QBitmap, not a pointer. -
But how to set 2 images and draw on top image?