Results 1 to 5 of 5

Thread: Repainting/Refreshing Layout after one QWidget * has changed

  1. #1
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Repainting/Refreshing Layout after one QWidget * has changed

    Hi,

    I have a layout filled with 2 widgets.
    I would like to replace one of the widgets of the layout using a signal/slot mechanism.

    What do I need to do so that the layout is repainted/refreshed using the new widget after the widget has been changed ?

    Qt Code:
    1. DriverView::DriverView( QWidget* parent ) :
    2. QWidget( parent )
    3. {
    4. // Title
    5. title = new TitleFrame(this,"Actual Driver");
    6. // Body
    7. body = driverFactory()->driverUserInterface(driverFactory()->currentDriver());
    8.  
    9. // Layout
    10. QVBoxLayout *mainLayout = new QVBoxLayout;
    11. mainLayout->addWidget(title);
    12. mainLayout->addWidget(body);
    13. mainLayout->setContentsMargins (0, 0, 0, 0);
    14. setLayout(mainLayout);
    15.  
    16. connect(driverFactory(),SIGNAL(driverHasChanged()), this, SLOT(refreshDriverView()));
    17. }
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. void
    2. DriverView::refreshDriverView() {
    3. body = driverFactory()->driverUserInterface(driverFactory()->currentDriver());
    4. // repaint(); doesn't work
    5. // update(); doesn't work
    6. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Repainting/Refreshing Layout after one QWidget * has changed

    You only change the body variable. Qt still has a pointer to the old widget. See QStackedWidget and QStackedLayout. Also don't forget to show the new widget.

  3. #3
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Repainting/Refreshing Layout after one QWidget * has changed

    Is there a way to tell QT to use the pointer on the new widget instead of the pointer of the old one ?

    Alternatively is it possible to delete the entire layout and create a new one ?

  4. #4
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Repainting/Refreshing Layout after one QWidget * has changed

    This seems to work:

    Qt Code:
    1. void
    2. DriverView::refreshDriverView() {
    3. body->hide();
    4. mainLayout->removeWidget(body);
    5. body = driverFactory()->driverUserInterface(driverFactory()->currentDriver());
    6. mainLayout->addWidget(body);
    7. body->show();
    8. }
    To copy to clipboard, switch view to plain text mode 

    Is there anything that speeks against this ?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Repainting/Refreshing Layout after one QWidget * has changed

    Quote Originally Posted by schall_l View Post
    Is there anything that speeks against this ?
    Where do you get rid of unused widgets?

Similar Threads

  1. changing layout of a widget
    By mikro in forum Qt Programming
    Replies: 10
    Last Post: 4th August 2009, 20:21
  2. Dynamic updates of a QWidget in a QScrollArea
    By plamkata in forum Qt Programming
    Replies: 2
    Last Post: 20th July 2008, 23:45
  3. Qt layout memory issue
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 25th August 2007, 17:11
  4. "dynamic" layout
    By hulk in forum Qt Programming
    Replies: 2
    Last Post: 9th May 2006, 07:16
  5. QT4 layout of complex dialog is very slow
    By cboles in forum Qt Programming
    Replies: 15
    Last Post: 28th April 2006, 19:57

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.