Search code examples
qtqwidgetqmainwindow

What to use with Qt for independent windows: a QDialog, a QWindow or a QMainWindow?


I am making my first steps with Qt. As an exercise, I am writing a GUI for a many-core processor, and individual cores are shown in a separate window. From this window, there may be several copies, with their independent life, including menus, status line, etc. That is, they are essentially like a QMainWindow, but having a QMoreMainWindow :). Might be any side effect if I use QMainWindow several times?


Solution

  • Nothing prevents you from using any of them for anything. They do have different roles and properties:

    • QMainWindow is just that: a main window. It has a toolbar, dockwidgets, a menu bar, a status bar, and a central widget. If you don't need all (most of) those things, you clearly don't want a QMainWindow.
    • QWindow is a barebones object in which is useful if you don't want/need QWidget's functionality.
    • QDialog is meant to be used for pop-up windows (i.e. "dialogs") like a messagebox or an open file dialog.
    • QWidget is the basic window or window element. If in doubt, use this.

    Reading your question, it seems you want each of those windows to be a QMainWindow. Note I'd still prefer a custom QWidget with only the parts I needed if I were you. Adding a statusbar and menu isn't that much code.