Updating a Widget and repainting
-
I am designing a UI made up of 3 components; a header panel across the top, a button panel down the right side, and a main content panel taking up the rest of the screen, like so:
The Header and the Button Panel stay the same, but the content panel should switch between a couple different widgets. Is there a way to replace and repaint the widget on the screen without adding it to the layout again?
This is the code I use to layout my widgets:
mainLayout = new QGridLayout; mainLayout->setMargin(0); mainLayout->setSpacing(0); mainLayout->addWidget(headerPnl, 0, 0, 1, 7); mainLayout->addWidget(contentPnl, 1, 0, 10, 6); mainLayout->addWidget(buttonPnl, 1, 6, 10, 1); this->setLayout(mainLayout);
This was my attempt to implement a
setContentPnl
method, but it doesn't seem to work. Nothing is replaced and the UI doesn't change.void MainWidget::setContentPnl(QWidget *content){ contentPnl = content; contentPnl.repaint(); contentPnl.update(); }
Is there a way I can point my contentPnl to different widgets, and update the screen accordingly?
-
Hi
When you say " switch between a couple different widgets"
you mean like flipping pages ?
In that case, http://doc.qt.io/qt-5/qstackedwidget.html
will make that easy.if you mean to actually replace the widget, you have to take it from layout and
insert new one.Can you explain why u need to replace the widget ?
is it sort of a preview of what is selected in Button panel or
what does it do for app? -
Hi
When you say " switch between a couple different widgets"
you mean like flipping pages ?
In that case, http://doc.qt.io/qt-5/qstackedwidget.html
will make that easy.if you mean to actually replace the widget, you have to take it from layout and
insert new one.Can you explain why u need to replace the widget ?
is it sort of a preview of what is selected in Button panel or
what does it do for app?@mrjj I mean to actually replace it. The app is meant to keep the header and button panel static, ie always there, always in the same place, and always looking the same. The only part of the screen that changes (as a result of different buttons being pressed) is the content panel.
I suppose I will have to keep a reference to the layout and just remove and add when necessary. Thanks.
-
@mrjj I mean to actually replace it. The app is meant to keep the header and button panel static, ie always there, always in the same place, and always looking the same. The only part of the screen that changes (as a result of different buttons being pressed) is the content panel.
I suppose I will have to keep a reference to the layout and just remove and add when necessary. Thanks.
@Smeeth
ok. make sure to use
http://doc.qt.io/qt-5/qlayout.html#takeAt -
@mrjj I mean to actually replace it. The app is meant to keep the header and button panel static, ie always there, always in the same place, and always looking the same. The only part of the screen that changes (as a result of different buttons being pressed) is the content panel.
I suppose I will have to keep a reference to the layout and just remove and add when necessary. Thanks.