Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How can i update a widget live



  • I have a QWidget that displays information from database. I want to make it so when i go back onto that QWidget it recalls it basically.

    At the moment I've done this by putting all the widgets (buttons, labels etc) in a frame and deleting and redrawing this, however I was thinking there must be a better method



  • @benyeyeye
    Hi there.

    I don't think anyone can answer this without clarifying the information you give. What widgets, how are they connected to the database, are you using model-view etc.? For example, QTableView is commonly used to display multiple rows & columns in a visual table from a database model, or QDataWidgetMapper can be used if you want to diaply information about just one row, with separate widgets for each of the columns.



  • @JonB
    One of the times - not connected to the database - Is where i have a singular button in a frame. when pressed i want that button to be removed and 4 different buttons in its place

    The other case i think i may replace with a QTableView instead as this seems more suitable



  • @benyeyeye said in How can i update a widget live:

    Is where i have a singular button in a frame. when pressed i want that button to be removed and 4 different buttons in its place

    You could do this in a number of ways:

    • To do it literally, you could use a layout's removeWidget() to remove the button and addWidget() to add a bunch of new ones.

    • You could use a button/widget's show/hide/setVisible() methods to hide the first button and show the other ones.

    • You could use a QStackedWidget to swap between one widget having just the first button and another widget having the three other buttons. A QStackedWidget shows only one widget at a time from a collection of widgets.


Log in to reply