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
Forum Updated to NodeBB v4.3 + New Features

Use QPainter with QPixmap contain QImage

Scheduled Pinned Locked Moved Solved General and Desktop
qpainterqpixmapqimage
6 Posts 2 Posters 9.1k Views 1 Watching
  • 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 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 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
      1
      • ? A Former User

        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 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 last edited by
          #4

          You have a typo in your code:

          QPainter *painter(&pix);

          Must be:

          QPainter painter(&pix);
          
          K 1 Reply Last reply
          1
          • ? A Former User

            You have a typo in your code:

            QPainter *painter(&pix);

            Must be:

            QPainter painter(&pix);
            
            K Offline
            K Offline
            kevin32
            wrote on last edited by
            #5

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

            ? 1 Reply Last reply
            0
            • K kevin32

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

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              @kevin32 Great :)

              1 Reply Last reply
              0

              • Login

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