Main window class vs widget class



  • Can someone please explain the detail difference between main window class and widget class in qt. While creating a project which one to choose for what ?



  • Main window has a status bar, menu bar and a central widget.
    the other element such as push button, label,slider and ... are widgets.



  • hi
    You use the main windows class to create the body of an application.
    In case of other control push button,label etc inherit of widget, if you want create a custom view you can inherit of widget, include controls, create and implemented new functionality.


  • Moderators

    When working with widgets the practical choice is between QMainWindow, QWidget and QDialog.

    The QDialog choice is obvious for, well, dialogs. It includes and exec() method to start a local loop and has methods to standard dialog actions - accept and reject (ok/cancel).

    QMainWindow has features for building a main app experience. It has built-in specialized layout for housing status and tool bars. It also has a powerful docking capabilities for creating dynamic app layouts using QDockWidgets.

    QWidget is the generic choice when you don't need any of the above capabilities. This is often true for various tool windows, widgets meant to be embedded in the QDockWidgets and all the windows types that don't have rich widget-based UI eg. games or visualization windows.

    Depending on an app type there's usually a single QMainWidget used for the main app window, several smaller QWidget based windows as docks, visualization and tool windows and occasional QDialogs for "talking" to the user.


Log in to reply
 

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