Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved Use QPainter with QPixmap contain QImage

    General and Desktop
    qpainter qpixmap qimage
    2
    6
    8537
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      kevin32 last edited by A Former User

      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 :)

      1 Reply Last reply Reply Quote 0
      • ?
        A Former User last edited by

        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);
        
        K 1 Reply Last reply Reply Quote 1
        • K
          kevin32 @Guest last edited by

          @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?

          1 Reply Last reply Reply Quote 0
          • ?
            A Former User last edited by

            You have a typo in your code:

            QPainter *painter(&pix);

            Must be:

            QPainter painter(&pix);
            
            K 1 Reply Last reply Reply Quote 1
            • K
              kevin32 @Guest last edited by

              @Wieland thank you very much again, work very well :)

              ? 1 Reply Last reply Reply Quote 0
              • ?
                A Former User @kevin32 last edited by

                @kevin32 Great :)

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post