Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Use QPainter with QPixmap contain QImage

Use QPainter with QPixmap contain QImage

Scheduled Pinned Locked Moved Solved General and Desktop
qpainterqpixmapqimage
6 Posts 2 Posters 9.1k Views
  • 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 Offline
    K Offline
    kevin32
    wrote on 29 May 2016, 16:01 last edited by A Former User
    #1

    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
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 29 May 2016, 16:29 last edited by
      #2

      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 29 May 2016, 16:39
      1
      • ? A Former User
        29 May 2016, 16:29

        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 Offline
        K Offline
        kevin32
        wrote on 29 May 2016, 16:39 last edited by
        #3

        @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
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on 29 May 2016, 16:58 last edited by
          #4

          You have a typo in your code:

          QPainter *painter(&pix);

          Must be:

          QPainter painter(&pix);
          
          K 1 Reply Last reply 29 May 2016, 17:44
          1
          • ? A Former User
            29 May 2016, 16:58

            You have a typo in your code:

            QPainter *painter(&pix);

            Must be:

            QPainter painter(&pix);
            
            K Offline
            K Offline
            kevin32
            wrote on 29 May 2016, 17:44 last edited by
            #5

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

            ? 1 Reply Last reply 29 May 2016, 17:47
            0
            • K kevin32
              29 May 2016, 17:44

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

              ? Offline
              ? Offline
              A Former User
              wrote on 29 May 2016, 17:47 last edited by
              #6

              @kevin32 Great :)

              1 Reply Last reply
              0

              4/6

              29 May 2016, 16:58

              • Login

              • Login or register to search.
              4 out of 6
              • First post
                4/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved