Results 1 to 5 of 5

Thread: Resizing QLabel inside ResizeEvent

  1. #1

    Default Resizing QLabel inside ResizeEvent

    Hello, I've been reading about what I'm gonna ask, but I didn't find a solution.

    I have a QImage on a QLabel, and I want to resize that image (and the QLabel, of course) when the window of my App is resized, all I have read is that I have to use layouts, but I don't understand how, cause the adjustSize() layout only changes the position of my label and what I want is to change it label->width() and label->height().

    I have a little code that override the virtual method resizeEvent:

    Qt Code:
    1. void MainWindow::resizeEvent(QResizeEvent *event){
    2.  
    3. QSize oldSize = event->oldSize();
    4. QSize actualSize = event->size();
    5.  
    6. if(ui->label->isVisible()){
    7.  
    8. double width = actualSize.width() / (double)oldSize.width(),
    9. height = actualSize.height() / (double)oldSize.height();
    10.  
    11. ui->label->resize(ui->label->size().width() * width,
    12. ui->label->size().height() * height);
    13. showImage(actualImage);
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    but it doesn't work properly, it resizes the photo, but when I resize the window many times, the label is getting smaller each time until it disappears. I'm pretty sure that the problem here is about the int var, because it loses information each time I resize.

    Which is the best way to do what I want?

    Thanks!
    Last edited by alexrn; 24th March 2016 at 20:06.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Resizing QLabel inside ResizeEvent

    Put the QLabel in a layout applied to the MainWindow container widget.
    Set the QLabel's scaledContent property.

  3. #3

    Default Re: Resizing QLabel inside ResizeEvent

    Quote Originally Posted by ChrisW67 View Post
    Put the QLabel in a layout applied to the MainWindow container widget.
    Set the QLabel's scaledContent property.
    Hi, thanks for answering,

    I tried your solution, but it didn't work for me, the scaledContent property only resizes the photo when I set the Pixmap into the QLabel, but I do that manually, so I think it is not needed here. As I said, what I want is the QLabel resizing with the App window. I don't know if I'm explaining well what I mean.

    When I try, for example, a vertical layout, my QLabel expands automatically, and I don't want that, I want it in a specific side.

    Regards.
    Last edited by alexrn; 25th March 2016 at 14:40.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Resizing QLabel inside ResizeEvent

    As I said, what I want is the QLabel resizing with the App window
    When I try, for example, a vertical layout, my QLabel expands automatically, and I don't want that, I want it in a specific side.
    So you want the QLabel to simultaneously resize with the containing window and not resize with the containing window? Perhaps you can see the potential for confusion.

    Put the QLabel in a QGridLayout with some spacers or other widgets in the other cells and set the stretch factors.
    Last edited by ChrisW67; 25th March 2016 at 20:47.

  5. #5

    Default Re: Resizing QLabel inside ResizeEvent

    Quote Originally Posted by ChrisW67 View Post
    So you want the QLabel to simultaneously resize with the containing window and not resize with the containing window? Perhaps you can see the potential for confusion.

    Put the QLabel in a QGridLayout with some spacers or other widgets in the other cells and set the stretch factors.
    I wanted it to resize, but not to expand at the whole window, using the stretch factors did the trick, thanks so much!

Similar Threads

  1. Resizing a QTreeWidgetItem with a widget inside
    By NullPointer in forum Newbie
    Replies: 1
    Last Post: 16th January 2012, 02:20
  2. Resizing QGraphicsView inside a QGridLayout
    By mckinnon in forum Newbie
    Replies: 3
    Last Post: 9th September 2010, 10:15
  3. resizeEvent - resizing unproportionally
    By Tomasz in forum Newbie
    Replies: 7
    Last Post: 16th August 2010, 23:52
  4. Resizing QTableView inside a QTabWidget
    By Aslan in forum Newbie
    Replies: 2
    Last Post: 29th May 2010, 14:50
  5. Image on QLabel and resizeEvent
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 12th September 2008, 09:32

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.