Results 1 to 2 of 2

Thread: Qlabel pixmap and resize pixmap, and repaint() not working

  1. #1
    Join Date
    Dec 2019
    Qt products
    Unix/X11 Windows

    Default Qlabel pixmap and resize pixmap, and repaint() not working

    Hi . my code is
    Qt Code:
    1. back.load(":/images/back.png");
    2. label = new QLabel(this);
    3. label->setGeometry(0,0,142,192);
    5. label->setPixmap(back);
    6. setStyleSheet("background-color:red"); // so far so good
    7. // but i want to change size pixmap after load (for example onclick event)
    8. label->pixmap()->scaled(QSize(100, 297));
    9. label->repaint();
    10. // noting change size with or another
    To copy to clipboard, switch view to plain text mode 

    I wantto change pixmap width after loading in label , because I use two pixmap for one label. I want to the pixmap of label inside to change , Whichever it can. I mean , what's inside pixmap that moment
    in other words, I want to change size which pixmap is present in the label, without knowing what pixmap is...

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 678 Times in 668 Posts
    Qt products
    Windows Android

    Default Re: Qlabel pixmap and resize pixmap, and repaint() not working

    label->pixmap()->scaled(QSize(100, 297))
    This code does nothing to the pixmap that is stored on the label. label->pixmap() returns a pointer to the pixmap on the label. QPixmap::scaled() returns a scaled copy of that pixmap, which is immediately thrown away as soon as the statement ends.

    What you want is this:

    Qt Code:
    1. label->setPixmap( label->pixmap()->scaled( QSize( 100, 297 ) ) );
    To copy to clipboard, switch view to plain text mode 

    You do not need the repaint() call; the label will automatically repaint itself after a new pixmap is set.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    sevketk (17th December 2019)

Similar Threads

  1. Replies: 8
    Last Post: 23rd April 2017, 01:00
  2. QLabel| Pixmap Delay
    By vProgramm in forum Newbie
    Replies: 3
    Last Post: 30th January 2015, 01:45
  3. Replies: 1
    Last Post: 19th April 2011, 12:17
  4. Pixmap updating QLabel
    By Matt in forum Newbie
    Replies: 11
    Last Post: 17th August 2010, 22:11
  5. empty pixmap as a QLabel
    By tommy in forum Qt Programming
    Replies: 16
    Last Post: 11th December 2007, 22:15


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.