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. QPixmap or QImage exchange the buffers

QPixmap or QImage exchange the buffers

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 2.2k 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.
  • H Offline
    H Offline
    heatblazer
    wrote on last edited by
    #1

    Hello, I am interested in the following topic: Can I exchange the QPixmap/QImage buffers or source file? Consider this small code:
    @
    static inline void CellOnPaint(QPainter* qp,
    const QStyleOptionGraphicsItem* qsi,
    QWidget* wd, QGraphicsItem* ari ) {
    MY_UNUSED(qp,qsi,wd,ari)
    QRectF rec = ((ActionItem*)ari)->boundingRect();
    QPixmap door = ((ActionItem)ari)->getMyPixmap();
    QImage eframe = door->toImage();
    qp->drawImage(rec, eframe);
    wd->update(); //needed
    }
    @

    WHere:

    @
    getMyPixmap()
    @

    is rturning a private member from my custom ActionItem class. The member is set in the construction, kind of

    @
    ActionItem* a1 = new ActionItem(QPixmap(":/res/p1.png"...));
    @

    @
    a1->setNewPixmap(":/res/p2.png");
    @

    Now the call to CellOnPaint will display "p2.png". BUt how to exchange the buffers?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ckakman
      wrote on last edited by
      #2

      Hi,

      I didn't understand what you meant by exchanging buffers. Where is a buffer in the code you have provided?

      1 Reply Last reply
      0
      • H Offline
        H Offline
        heatblazer
        wrote on last edited by
        #3

        Maybe I post it bad. Consider the CellOnPaint. See line 6. It assigns per call the ref from ActionItems private pixmap, which is set in the constructor and is known. I want to just exchange the pixmap. Ive wrote setNewQPix(QPix...) but on the call the program fails.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ckakman
          wrote on last edited by
          #4

          Check out the QPixmap constructors. If you want to pass in a file path, use the constructor that accepts a QString. Note there is another constructor that accepts const char* but that one expects data not a path.

          Try a1->setNewQPixmap( QPixmap(QString( ":/...png") ) ).

          1 Reply Last reply
          0
          • H Offline
            H Offline
            heatblazer
            wrote on last edited by
            #5

            Let me show you the full code of the setQpix...
            @
            static inline void SwapOn(QGraphicsSceneMouseEvent* me,
            QGraphicsItem* ari) {
            ((ActionItem*)ari)->setMyPixmap(
            MainWindow::getActionItemByName("Wolf1")->getPixmapRes()
            );
            }
            @
            Sorry, its a bit hard to read, I suppose, but the idea is qute, simple, take the QGaraphics item clicked, and set its pixmap to another QGraphics derivate found by name from a heap simulation list of items. I`ll give a try to your suggestion.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              ckakman
              wrote on last edited by
              #6

              I am sorry but you are not showing me anything here:

              • What do you pass in to that function? What does getPixmapRes() mean? get Pixmap Resolution? What does it return?
              • How is the setNewPixmap() or setMyPixmap() or setQpix... is implemented?
              • What does it mean that the program fails? Does it crash? Does it fail to compile? Does it fail to link?

              Here is how a QPixmap is "updated":http://doc.qt.io/qt-5/qpixmap.html#QPixmap-6:
              @
              QPixmap a;
              QPixmap b;
              b = a;
              @

              1 Reply Last reply
              0
              • H Offline
                H Offline
                heatblazer
                wrote on last edited by
                #7

                Sorry I kind of suck at forums :)
                @
                void ActionItem::setMyPixmap(QString s) {
                pixmap = new QPixmap(s);
                }

                QPixmap* ActionItem::getMyPixmap()
                {
                return pixmap;
                }
                @
                Let me give a try to your suggestion and I`ll write back. Probably your help was enough. Hope so. :)

                [quote author="ckakman" date="1421180662"]I am sorry but you are not showing me anything here:

                • What do you pass in to that function? What does getPixmapRes() mean? get Pixmap Resolution? What does it return?
                • How is the setNewPixmap() or setMyPixmap() or setQpix... is implemented?
                • What does it mean that the program fails? Does it crash? Does it fail to compile? Does it fail to link?

                Here is how a QPixmap is "updated":http://doc.qt.io/qt-5/qpixmap.html#QPixmap-6:
                @
                QPixmap a;
                QPixmap b;
                b = a;
                @[/quote]

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  ckakman
                  wrote on last edited by
                  #8

                  You don't need a pointer to QPixmap as member variable. QPixmap is implicitly shared.

                  @
                  private:
                  QPixmap pixmap;
                  @

                  If you somehow have to use a pointer, than you have a memory leak there. Delete the pixmap before assigning a new one.

                  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