PyQt5 can be used to create desktop applications in Python. It lets you build a graphical user interface (GUI) for your Python program.

A Qt window is not always a normal window. Window flags change how it behaves: stays on top, no title bar, full screen, a small popup. The flags are set when you create the window or with setWindowFlags() after.

In a desktop, not all windows are the same. Some windows can not be maximized (like a popup). Some windows only exist in full screen mode (games). A PyQt window can be configured using window flags. After ‘configuration’, it will create another type of window.

pyqt window flags

Some windows don’t have a close window button [x], others windows don’t have a title bar and so on. All kind of windows are possible on a desktop operating system.

If you use the Chrome web browser, you may see a different type of title bar, custom from other desktop apps on your computer.

method override

You would set a windows flags using this method:

window.setWindowFlags(flags)
where flags is defined as
flags = Qt.WindowFlags()

PyQt window flags

PyQt has these window flags:

  • Qt.MSWindowsFixedSizeDialogHint
  • Qt.X11BypassWindowManagerHint
  • Qt.FramelessWindowHint
  • Qt.WindowTitleHint
  • Qt.WindowSystemMenuHint
  • Qt.WindowMinimizeButtonHint
  • Qt.WindowMaximizeButtonHint
  • Qt.WindowCloseButtonHint
  • Qt.WindowContextHelpButtonHint
  • Qt.WindowShadeButtonHint
  • Qt.WindowStaysOnTopHint
  • Qt.WindowStaysOnBottomHint
  • Qt.CustomizeWindowHint

Windows

These can be applied to windows.
PyQt has not just one, but many types of windows:

  • Qt.Window
  • Qt.Dialog
  • Qt.Sheet
  • Qt.Drawer
  • Qt.Popup
  • Qt.Tool
  • Qt.ToolTip
  • Qt.SplashScreen

The flags you will use

  • QtCore.Qt.FramelessWindowHint removes the title bar and the border.
  • QtCore.Qt.WindowStaysOnTopHint keeps the window above the others.
  • QtCore.Qt.Dialog makes a small window without the normal buttons.
  • QtCore.Qt.CustomizeWindowHint lets you pick which buttons appear.
  • QtCore.Qt.Window is the plain window, it is the default.
  • setWindowTitle('My app') sets the text in the title bar.
  • setWindowIcon(QIcon('app.png')) sets the icon.

Flags have to be set before the window is shown. After that the window may be hidden and shown again for the change to take effect.

The fastest way to learn this is to write it yourself. The PyChallenge exercises run in your browser, no install needed.