[SOLVED] [N00b] Need tips on creating UI



  • Hello Qt Devs!

    I am developing a front-end to a PostgreSQL DB. I have some ideas for the design of the UI, but have no idea on how to implement them. Here isi the situation.

    I have QMainWindow with Menu Bar. I want to have specific content appear in the MainWindow when I press some button in the Menu Bar.

    For instance, when I press "Start QA Instance", I have some widgets to appear below the menu bar. However, when I press on "Employee List", I want the widgets of "Start QA Instance" to disappear and have the widgets pertaining to "Employee List" to appear. Anyway to do that?

    Thanks,



  • Using "signals and slots":http://doc.qt.nokia.com/4.7/signalsandslots.html you can control events. Use "QWidget":http://doc.qt.nokia.com/latest/qwidget.html methods setVisible(), show(), hide() to control the visibility of your widgets.

    Cheers,
    Leon



  • Create a QWidget subclass, which might contain any other widgets using Q*Layout and QWidget::setLayout(), for every set of widgets you want to display and add it to a QStackedWidget which becomes the central widget.

    Now you can freely switch betweens those "widget sets" using QStackedWidget::setCurrentIndex() or QStackedWidget::setCurrentWidget().



  • For cases where I have fewer than 6 or 8 sets of "some widgets" that I switch between, I tend to use a QTabWidget.

    Many more than that, then I use QStackedWidget, and switch between the pages with QComboBox. It is easy to connect the QComboBox's currentIndexChanged(int) signal to the QStackedWidget's setCurrentIndex(int) slot using the Designer, or simply your QMainWindow's constructor.

    Or, if I have plenty of room and will be switching frequently between sets of widgets, I'll put a QListWidget (QListView is usually too heavy for this) alongside and make the same connection as I would for the QComboBox.



  • Thanks for the tips!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.