Results 1 to 17 of 17

Thread: Change the size of pixmap in a label

  1. #1
    Join Date
    Mar 2010
    Posts
    56
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Change the size of pixmap in a label


  3. #3
    Join Date
    Mar 2010
    Posts
    56
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Change the size of pixmap in a label

    The Qt documentation is one of the best. I wonder why people don't read it.

    Returns a copy of the image scaled to a rectangle with the given width and height

  5. #5
    Join Date
    Mar 2010
    Posts
    56
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Change the size of pixmap in a label

    you're right, thanks very much

  6. #6
    Join Date
    Mar 2010
    Posts
    56
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

  7. #7
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Change the size of pixmap in a label

    What happens if you use:

    Qt Code:
    1. imageLabel->setPixmap(QPixmap::fromImage(image.scaled(200,200)));
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Mar 2010
    Posts
    56
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Change the size of pixmap in a label

    it's work but this or that "image = image.scaled(200,200,Qt::IgnoreAspectRatio,Qt::Fas tTransformation);" is the same. i tallking about the scaled function for pixmap.

  9. #9
    Join Date
    Mar 2010
    Posts
    56
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Change the size of pixmap in a label

    it's work, but this is the same of "image = image.scaled(200,200,Qt::IgnoreAspectRatio,Qt::Fas tTransformation);".
    Why i can't use the scaled function of pixmap.

  10. #10
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Change the size of pixmap in a label

    Who said you can't?

  11. #11
    Join Date
    Mar 2010
    Posts
    56
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Change the size of pixmap in a label

    i tried and the image doesn't resize! :S

  12. #12
    Join Date
    Mar 2010
    Posts
    56
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Change the size of pixmap in a label

    Cpp Code:
    1. #include "mainwindow.h"
    2. #include <QtGui>
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QWidget(parent)
    6. {
    7. QHBoxLayout *lay=new QHBoxLayout;
    8. setLayout(lay);
    9. QImage image("comando.jpg");
    10. QLabel *imageLabel = new QLabel(this);
    11. lay->addWidget(imageLabel);
    12. imageLabel->setPixmap(QPixmap::fromImage(image.scaled(400,400,Qt::KeepAspectRatio,Qt::FastTransformation)));
    13. qDebug() << imageLabel->pixmap()->size();
    14. }
    15.  
    16. MainWindow::~MainWindow()
    17. {
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 

    Now all the time i want change the imagelabel i will need to set again the pixmap :s I resize the image all the time that the user will change the mainwindow size.

  13. The following user says thank you to metRo_ for this useful post:

    pavanbarot (29th July 2010)

  14. #13
    Join Date
    Apr 2011
    Location
    San Francisco Bay area
    Posts
    5
    Qt products
    Platforms
    MacOS X Windows

    Default Re: Change the size of pixmap in a label

    metRo_: Yes, that is true, whether you resize the image and extract its pixmap each time, or save the extracted pixmap and resize the pixmap each time. If the label can change size and you want the pixmap to change size with it, somebody has to resize the pixmap. In Qt, that somebody is you.

    One option is to subclass QLabel and override the resizeEvent() method. Within that, resize the pixmap (from the original! don't keep resizing the resized image!), and call setPixmap(). So you probably want a setOriginalPixmap() method also, in case you want to change the image that's on the the label.

    Qt Code:
    1. void setOriginalPixmap(QPixmap *pixmap)
    2. {
    3. if (original_pixmap)
    4. delete original_pixmap;
    5. original_pixmap = pixmap;
    6. setScaledPixmap();
    7. }
    8.  
    9. void resizeEvent (QResizeEvent *event)
    10. {
    11. setScaledPixmap();
    12. }
    13.  
    14. void setScaledPixmap (void)
    15. {
    16. scaled_pixmap = original_pixmap->scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    17. setPixmap(scaled_pixmap);
    18. }
    To copy to clipboard, switch view to plain text mode 

  15. #14
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Change the size of pixmap in a label

    @dflo: Welcome!

    But this thread is quite old to be picked up, don't you think?

    Joh

  16. #15
    Join Date
    Apr 2011
    Location
    San Francisco Bay area
    Posts
    5
    Qt products
    Platforms
    MacOS X Windows

    Default Re: Change the size of pixmap in a label

    Yeah probably. I was looking for something else, and meanwhile I found some questions I could answer. Maybe metRo_ put his project on hold and will come back to it?

    Thanks for the welcome!

  17. #16
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Change the size of pixmap in a label

    Yeah :-> Just don't be disappointed if nothing happens - that's all I wanted to say.

    Happy coding,

    Johannes

  18. #17
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Change the size of pixmap in a label

    First set the pixmap to the label.
    Then, set the size of the label by:-
    Qt Code:
    1. QLabel label=new QLabel;
    2. label.setPixmap(pix);
    3. label.setFixedSize(w,h);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. label - pixmap - problem
    By qwrhiobasdbgghoasdf in forum Newbie
    Replies: 5
    Last Post: 16th September 2010, 00:29
  2. How do i change images? Qt creator label>pixmap
    By QueenZ in forum Qt Programming
    Replies: 4
    Last Post: 8th February 2010, 04:44
  3. How to change the Label text
    By grsandeep85 in forum Qt Programming
    Replies: 2
    Last Post: 15th September 2009, 12:57
  4. Replies: 1
    Last Post: 24th October 2006, 16:40
  5. change font size and button size of QMessageBox
    By nass in forum Qt Programming
    Replies: 6
    Last Post: 13th September 2006, 19:16

Bookmarks

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.