Use QPainter with QPixmap contain QImage
-
Hi everyone, again me can you help me please ?
I convert Mat image to qimage and display in qlabel
QImage img= QImage((uchar*) frame.data, frame.cols, frame.rows, frame.step, QImage::Format_RGB888); // create Qpixmap from Qimage QPixmap pix = QPixmap::fromImage(img); // display the pixmap on the label ui->label->setPixmap(pix);
I want to use painter for display other image, my code dont work
QPixmap pix = QPixmap::fromImage(img); // problem here QPainter *painter=new QPainter(pix); painter->drawPixmap(0, 0, 100, 100, QPixmap("C://Users//user//Pictures//a.png")); painter->end(); ui->label->setPixmap(*pix);
error: no matching function for call to 'QPainter::QPainter(QPixmap&)' QPainter *painter=new QPainter(pix); ^ ..\Double_video\mainwindow.cpp:44:43: note: candidates are: In file included from ..\..\..\..\Qt\5.5\mingw492_32\include\QtGui/QPainter:1:0, from ..\Double_video\mainwindow.h:4, from ..\Double_video\mainwindow.cpp:1: ..\..\..\..\Qt\5.5\mingw492_32\include\QtGui/qpainter.h:117:14: note: QPainter::QPainter(QPaintDevice*) explicit QPainter(QPaintDevice *); ^ ..\..\..\..\Qt\5.5\mingw492_32\include\QtGui/qpainter.h:117:14: note: no known conversion for argument 1 from 'QPixmap' to 'QPaintDevice*' ..\..\..\..\Qt\5.5\mingw492_32\include\QtGui/qpainter.h:116:5: note: QPainter::QPainter() QPainter(); ^
how use qpainter with existing qpixmap and no create new ?
thanks :)
-
It's
QPainter::QPainter(QPaintDevice *device)
so instead of...QPainter *painter=new QPainter(pix);
it has to be...
QPainter *painter=new QPainter(&pix);
BTW: Do you really need to create the painter in this way? Maybe it's better to just:
QPainter painter(&pix);
-
It's
QPainter::QPainter(QPaintDevice *device)
so instead of...QPainter *painter=new QPainter(pix);
it has to be...
QPainter *painter=new QPainter(&pix);
BTW: Do you really need to create the painter in this way? Maybe it's better to just:
QPainter painter(&pix);
@Wieland thanks, but i have ```
error: cannot convert 'QPixmap*' to 'QPainter*' in initialization QPainter *painter(&pix);
// create Qpixmap from Qimage QPixmap pix = QPixmap::fromImage(img); QPainter *painter(&pix); painter->drawPixmap(0, 0, 100, 100, QPixmap("C://Users//user//Pictures//a.png")); painter->end(); ui->label->setPixmap(pix);
Have you a idea please?
-
You have a typo in your code:
QPainter *painter(&pix);
Must be:
QPainter painter(&pix);
-
You have a typo in your code:
QPainter *painter(&pix);
Must be:
QPainter painter(&pix);
-
@kevin32 Great :)