Results 1 to 7 of 7

Thread: How to update layout after widget visibility change ?

  1. #1
    Join Date
    Jun 2012
    Posts
    63
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default How to update layout after widget visibility change ?

    When I hide one widget in the program the layout is not updated/resized until I manually resize the window with a mouse.

    Is there a way to update/refresh layout after I hide widgets inside a layout ?

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to update layout after widget visibility change ?

    look at
    setSizeConstraint of Layout
    setSizeConstraint ( SizeConstraint )

    may be u need
    setSizeConstraint(QLayout::SetFixedSize);

    check the example
    http://harmattan-dev.nokia.com/docs/...extension.html
    "Behind every great fortune lies a crime" - Balzac

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to update layout after widget visibility change ?

    Quote Originally Posted by phenoboy View Post
    When I hide one widget in the program the layout is not updated/resized until I manually resize the window with a mouse.

    Is there a way to update/refresh layout after I hide widgets inside a layout ?
    Show the code please.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jun 2012
    Posts
    63
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to update layout after widget visibility change ?

    Quote Originally Posted by wysota View Post
    Show the code please.
    I think I narrowed down the code to this. MyLabel is inherited from QLabel. I want it to change size (to maximum space) when I resize the window. It looks like it is not resizing automatically after this resize event. Is there some method I'm missing here ?

    Qt Code:
    1. void MyLabel::resizeEvent(QResizeEvent* ev)
    2. {
    3. int minPointSize=14;
    4. const QSize& sz=ev->size();
    5. const QFont& fnt=font();
    6. QFont f=fnt;
    7.  
    8. qDebug() << "Resize event:" << sz << "pixelsize:" << f.pixelSize()
    9. << "." << f.pointSize();
    10.  
    11. f.setPointSize(sz.height()/2);
    12.  
    13. if (f.pointSize() < minPointSize) {
    14. f.setPointSize(minPointSize);
    15. }
    16.  
    17. setFont(f);
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to update layout after widget visibility change ?

    What exactly do you mean that it is not "resizing automatically"? A resizeEvent is triggered after a resize, not before a resize. If you get a resizeEvent then the widget has already been resized.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jun 2012
    Posts
    63
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to update layout after widget visibility change ?

    Quote Originally Posted by wysota View Post
    What exactly do you mean that it is not "resizing automatically"? A resizeEvent is triggered after a resize, not before a resize. If you get a resizeEvent then the widget has already been resized.
    Some more code.. The main widget contains three components (in different layouts). One is gauge, lcdnumber and a label. In this function I'm either showing gauge and hiding lcd or hiding gauge and showing lcd. Also I'm rearranging widgets because I want text label to be first. I was thinking that when layout is changed -> resize event is triggered and label is updated.

    Now what happens when switching to condition noGauge==false is that gauge is hidden and font is resized correctly BUT the window size doesn't change and text that label contains is not shown fully . Only when I resize main window then label gets resized correctly and it shows full text

    Qt Code:
    1. void switchView() {
    2. if (noGauge) {
    3. m_gauge->setVisible(true);
    4. ui->lcdNumber->setHidden(true);
    5. noGauge=false;
    6. } else {
    7. m_gauge->setVisible(false);
    8. ui->lcdNumber->setVisible(true);
    9. ui->layoutLCDTop->removeWidget(label);
    10. ui->layoutLCDTop->addWidget(label);
    11. ui->layoutLCDTop->addWidget(ui->lcdNumber);
    12.  
    13. noGauge=true;
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to update layout after widget visibility change ?

    Changing the widget position does not cause a resize. If you want to update widget contents, call update() on it and a paint event will be scheduled.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    phenoboy (10th September 2013)

Similar Threads

  1. DockWidgetArea change and layout direction change
    By mstegehu in forum Qt Programming
    Replies: 1
    Last Post: 21st February 2012, 21:24
  2. How to change a widget to other widget in layout?
    By Kevin Hoang in forum Qt Programming
    Replies: 2
    Last Post: 20th March 2010, 10:55
  3. QGroupBox visibility change trapping
    By lurky in forum Newbie
    Replies: 2
    Last Post: 10th September 2009, 09:07
  4. Button visibility and layout participation
    By DiamonDogX in forum Newbie
    Replies: 1
    Last Post: 2nd April 2009, 18:23
  5. Hide widget, but not change layout
    By dimaz in forum Qt Programming
    Replies: 3
    Last Post: 21st November 2008, 14:32

Tags for this Thread

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.