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

Move QPixmap to QLabel

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.8k 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.
  • S Offline
    S Offline
    stereomatching
    wrote on last edited by
    #1

    Could I move QPixmap into the QLabel?
    I haven't found any member function which support
    move semantics or some function could move the QPixmap into the QLabel
    even in Qt5.The original solution of QLabel is copy the
    QPixmap you pass into the function.

    If I haven't missed any fucntions Qt provided, what kind of
    technical reason QLabel do not support move semantics
    or just provide the users a simple function to send the resource into
    the QLabel but not copy.

    Thanks a lot

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuhamedAuda
      wrote on last edited by
      #2

      @ QLabel label;
      label.setPixmap(pixmap);@

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stereomatching
        wrote on last edited by
        #3

        Thanks, but this looks like copy
        According to the declaration
        setPixmap(QPixmap const &)
        Const& wouldn't increase reference count
        I don't think they will share the same resource

        and the implementation looks more like copy than move

        @
        void QLabel::setPixmap(const QPixmap &pixmap)
        {
        Q_D(QLabel);
        if (!d->pixmap || d->pixmap->cacheKey() != pixmap.cacheKey()) {
        d->clearContents();
        d->pixmap = new QPixmap(pixmap);
        }

        if (d->pixmap->depth() == 1 && !d->pixmap->mask())
            d->pixmap->setMask(*((QBitmap *)d->pixmap));
        
        d->updateLabel();
        

        }
        @

        looks like the QLabel will create a brand new copy of the QPixmap
        if the d->pixmap do not point to anything or they don't have the
        same cacheKey.

        But the behavior I want is something like
        @
        QPixmap *temp = origin_pixmap;
        origin_pixmap = new_pixmap;
        temp->release()
        @

        or
        @
        std::string A, B;
        //.............
        A = std::move(B);
        @

        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