Results 1 to 20 of 21

Thread: Reimplement of resizeEvent

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Reimplement of resizeEvent

    The easiest possible way is to let the label scale its contents:
    Qt Code:
    1. SLD::SLD(QWidget *parent, Qt::WFlags flags)
    2. : QMainWindow(parent, flags)
    3. {
    4. ui.setupUi(this);
    5. QLabel* label=new QLabel(this);
    6. label->setPixmap(QPixmap("Resources/CB.bmp"));
    7. label->setScaledContents(true); // let the label scale its contents
    8. setCentralWidget(label); // label will get automatically resized as a central widget
    9. }
    To copy to clipboard, switch view to plain text mode 

    If you need more intelligent scaling, like keeping aspect ratio or something, you might want to scale it by hand. This would be done by storing the image as a member variable, scaling it for example in resizeEvent() and setting the scaled image on the same label. I'd suggest doing it a bit delayed so that each and every resizeEvent() in a row doesn't scale and set a new image.

    Notice that you were creating new QLabel widgets again and again during every resize event! Also, Qt has a concept of layouts to handle geometries. You barely set geometries by hand.
    J-P Nurmi

  2. The following user says thank you to jpn for this useful post:

    Shawn (27th May 2007)

Similar Threads

  1. resizeEvent help pls
    By munna in forum Newbie
    Replies: 10
    Last Post: 9th July 2010, 08:38
  2. resizeEvent from parent to child?
    By ChasW in forum Qt Programming
    Replies: 3
    Last Post: 11th February 2007, 18:21
  3. Replies: 3
    Last Post: 27th November 2006, 09:56
  4. Reimplement QSplashScreen::drawContents
    By ucomesdag in forum Qt Programming
    Replies: 12
    Last Post: 24th November 2006, 09:39
  5. Question about resizeEvent
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 28th February 2006, 16:13

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
  •  
Qt is a trademark of The Qt Company.