Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Scale QPixmap has no effect
Forum Updated to NodeBB v4.3 + New Features

Scale QPixmap has no effect

Scheduled Pinned Locked Moved Solved Mobile and Embedded
4 Posts 3 Posters 1.0k Views 2 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.
  • T Offline
    T Offline
    thinkpad_32167
    wrote on last edited by kshegunov
    #1

    Hi guys,

    I am coding an app for my android tablet. I am trying to set a png image as background to my mainwindow. However, the scaled() fct doesn't resize the QPixmap to the right size.

    Here is my code :

    QPixmap bkgnd = QPixmap(":/images/0.png");
    QPixmap scaledPixmap = bkgnd.scaled(this->width(), this->height(),Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
        
    QPalette palette;
    QBrush brush = QBrush(scaledPixmap);
    palette.setBrush(QPalette::Background, brush);
    this->setPalette(palette);
    

    Thank you for your help !

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

      Hi and welcome to devnet,

      Are you by any chance doing that in the constructor ? If so that's normal. When the constructor is called the widget has no idea about the size it's going to have. You should rather do that in a showEvent reimplementation or maybe resizeEvent.

      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
      • kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #2

        Could you illustrate the issue with a screenshot, as we can have no idea what the correct size is?

        Read and abide by the Qt Code of Conduct

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

          Hi and welcome to devnet,

          Are you by any chance doing that in the constructor ? If so that's normal. When the constructor is called the widget has no idea about the size it's going to have. You should rather do that in a showEvent reimplementation or maybe resizeEvent.

          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
          • T Offline
            T Offline
            thinkpad_32167
            wrote on last edited by
            #4

            Wow you are right ! Now it works as expected !

            Thank you so much, I've been looking for a solution for like a week !

            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