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

Pixmap resize

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 23.4k Views 3 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.
  • O Offline
    O Offline
    ofmrew
    wrote on last edited by
    #1

    I am looking to use QPixmap in a double-buffering application and I need to resize it when my widget is resized; however, there is not resize member function. I have code that works where I delete the Pixmap and create a new one with the new size. The documentary and online commentary seem to indicate the the preferred method of allocating the QPixmap is using the statement "QPixmap name" and not "QPixmap name = new QPixmap (qrect)". The latter is easy to resize, but the second is not. If I use the former to create data member, the how do I resize it? (This is probably a simple C++ question, but my C++ is very rusty.)

    FlotisableF jsulmJ 2 Replies Last reply
    0
    • O ofmrew

      I am looking to use QPixmap in a double-buffering application and I need to resize it when my widget is resized; however, there is not resize member function. I have code that works where I delete the Pixmap and create a new one with the new size. The documentary and online commentary seem to indicate the the preferred method of allocating the QPixmap is using the statement "QPixmap name" and not "QPixmap name = new QPixmap (qrect)". The latter is easy to resize, but the second is not. If I use the former to create data member, the how do I resize it? (This is probably a simple C++ question, but my C++ is very rusty.)

      FlotisableF Offline
      FlotisableF Offline
      Flotisable
      wrote on last edited by
      #2

      @ofmrew
      have you tried QPixmap::scaled?
      read Pixmap Transformations for more information

      1 Reply Last reply
      2
      • O ofmrew

        I am looking to use QPixmap in a double-buffering application and I need to resize it when my widget is resized; however, there is not resize member function. I have code that works where I delete the Pixmap and create a new one with the new size. The documentary and online commentary seem to indicate the the preferred method of allocating the QPixmap is using the statement "QPixmap name" and not "QPixmap name = new QPixmap (qrect)". The latter is easy to resize, but the second is not. If I use the former to create data member, the how do I resize it? (This is probably a simple C++ question, but my C++ is very rusty.)

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @ofmrew Since QPixmap has a move assignment operator (http://doc.qt.io/qt-5/qpixmap.html#operator-eq-1) you can do:

        QPixmap pixmap;
        ...
        pixmap = pixmap.scaled(...);
        

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2
        • O Offline
          O Offline
          ofmrew
          wrote on last edited by
          #4

          Thanks to both, you got me thinking. Since the Pixmap will be used in an off-screen buffering operation and the aspect ratio will most likely be changed by the parent window being resized, the Pixmap should be redrawn, so scaling the old contents is inefficient. It look like

               pixmap = QPixmap(this->rect());
          

          is my best bet.

          Here, however, is a C++ question: If I define my pixmap to be a data member of a custom widget class using the statement "QPixmap pixmap" and then create a new Pixmap, where will the new one reside and what is its lifetime--I want it to last as long as my custom widget exists? Also, is the old one deleted or do I have a memory leak? (I told you my C++ is rusty.)

          FlotisableF 1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            It will be replaced.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • O ofmrew

              Thanks to both, you got me thinking. Since the Pixmap will be used in an off-screen buffering operation and the aspect ratio will most likely be changed by the parent window being resized, the Pixmap should be redrawn, so scaling the old contents is inefficient. It look like

                   pixmap = QPixmap(this->rect());
              

              is my best bet.

              Here, however, is a C++ question: If I define my pixmap to be a data member of a custom widget class using the statement "QPixmap pixmap" and then create a new Pixmap, where will the new one reside and what is its lifetime--I want it to last as long as my custom widget exists? Also, is the old one deleted or do I have a memory leak? (I told you my C++ is rusty.)

              FlotisableF Offline
              FlotisableF Offline
              Flotisable
              wrote on last edited by
              #6

              @ofmrew
              I think

              pixmap = QPixmap( this->rect() );
              

              is the same as

              pixmap = pixmap.scaled( this->rect() );
              

              except that the first one doesn't have any content

              as for the life time, both way just construct a temporary object, and it will be destructed after the assignment. since their data will be assigned to pixmap so it's fine that the temporary object being destructed.

              and as @SGaist said, the old data in pixmap will be replaced

              1 Reply Last reply
              2
              • O Offline
                O Offline
                ofmrew
                wrote on last edited by
                #7

                Thanks

                I got it to work.

                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