Qt
1 min
Overview #
This document is a practical Qt cheatsheet focused on frequently used snippets, flags, and core concepts encountered in real-world applications.
Qt is a cross-platform C++ framework (also available via Python bindings such as PySide and PyQt) following the WOCA principle (Write Once, Compile Anywhere). It is widely used for building desktop applications, GUIs, and embedded systems across Windows, Linux, and macOS.
Check if a QListWidgetItem is checkable #
is_checkable = bool(item.flags() & Qt.ItemIsUserCheckable)
Explanation
Qt.ItemIsUserCheckableis a flag, not a property.- You must test it using a bitwise AND (
&).
QListWidgetItemis not checkable by default. The checkbox will only appear if:
- the
Qt.ItemIsUserCheckableflag is set and- a check state is explicitly assigned using
setCheckState().
✅ Correct usage reminder:
item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
item.setCheckState(Qt.Unchecked)