Results 1 to 5 of 5

Thread: Resizing QLabel inside ResizeEvent

Threaded View

Previous Post Previous Post   Next Post Next Post
  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.

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