Qt Widgets Reference Documentation

40000 Chips

Drawing Utility Functions

Address Book

Overview

TableModel Class Definition

TableModel Class Implementation

AddressWidget Class Definition

AddressWidget Class Implementation

NewAddressTab Class Definition

NewAddressTab Class Implementation

AddDialog Class Definition

AddDialog Class Implementation

MainWindow Class Definition

MainWindow Class Implementation

main() Function

Affine Transformations

Analog Clock

AnalogClock Class Definition

AnalogClock Class Implementation

Apple Human Interface Guidelines

Application Main Window

Overview of the Main Window Classes

The Main Window Classes

Example Code

Basic Drawing Example

Window Class Definition

Window Class Implementation

RenderArea Class Definition

RenderArea Class Implementation

Basic Graphics Layouts Example

Window Class Definition

Window Class Implementation

LayoutItem Class Definition

LayoutItem Class Implementation

Basic Layouts Example

Running the Example

Dialog Class Definition

Dialog Class Implementation

Basic Sort/Filter Model Example

Calculator Example

Calculator Class Definition

Calculator Class Implementation

Button Class Definition

Button Class Implementation

Calendar Widget Example

Window Class Definition

Window Class Implementation

Changes to Qt Widgets

Kernel classes

The QWidget class

QDesktopWidget and QApplication::desktop()

QAction, QActionGroup

Widgets

The QAbstractButton class

The QComboBox class

The QDateTimeEdit class

ItemViews

The QAbstractItemView class

Styling Classes and related APIs

Style sheet changes

Utility Classes

QUndoCommand, QUndoStack, and QUndoGroup

Colliding Mice Example

Mouse Class Definition

Mouse Class Definition

The Main() Function

Combo Widget Mapper Example

Window Class Definition

Window Class Implementation

Summary and Further Reading

Completer Example

The Resource File

FileSystemModel Class Definition

FileSystemModel Class Implementation

MainWindow Class Definition

MainWindow Class Implementation

main() Function

Composition Modes

Cube RHI Widget Example

Custom Completer Example

Setting Up The Resource File

TextEdit Class Definition

TextEdit Class Implementation

MainWindow Class Definition

MainWindow Class Implementation

main() Function

Custom Sort/Filter Model Example

MySortFilterProxyModel Class Definition

MySortFilterProxyModel Class Implementation

Window Class Definition

Window Class Implementation

The Main() Function

Customizing Qt Widgets Using Style Sheets

box model

sub controls

The Box Model

Sub-controls

Design Patterns

Diagram Scene Example

MainWindow Class Definition

MainWindow Class Implementation

DiagramScene Class Definition

DiagramScene Class Implementation

DiagramItem Class Definition

DiagramItem Class Implementation

DiagramTextItem Class Definition

DiagramTextItem Implementation

Arrow Class Definition

Arrow Class Implementation

Dialog Windows

Drag and Drop Robot Example

Robot Class Definition

ColorItem Class Definition

The main() Function

Draggable Icons Example

DragWidget Class Definition

DragWidget Class Implementation

Draggable Text Example

Drop Site Example

DropArea Class Definition

DropArea Class Implementation

DropSiteWindow Class Definition

DropSiteWindow Class Implementation

The main() Function

Easing Curves Example

Editable Tree Model Example

Relations-between-internal-items

Relating-items-using-model-indexes

TreeItem::parent

TreeItem::child

TreeItem::data

TreeItem::setData

TreeModel::getItem

TreeModel::index

TreeModel::parent

TreeModel::data

TreeModel::setupModelData

Overview

Design

TreeItem Class Definition

TreeItem Class Implementation

TreeModel Class Definition

TreeModel Class Implementation

Testing the model

Elastic Nodes Example

Node Class Definition

Edge Class Definition

GraphWidget Class Definition

The main() Function

Fetch More Example

FileListModel Class Definition

FileListModel Class Implementation

Flow Layout Example

Running the Example

FlowLayout Class Definition

FlowLayout Class Implementation

Frozen Column Example

FreezeTableWidget Class Definition

FreezeTableWidget Class Implementation

Gestures in Widgets and Graphics View

Overview

Using Standard Gestures with Widgets

Handling Events

Standard Procedure for Event Handling

Example Event Handling

Creating Your Own Gesture Recognizer

Filtering Input Events

Custom Gestures

Resetting Gestures

Using a New Gesture Recognizer

Further Reading

Gestures in Qt Quick

Getting Started Programming with Qt Widgets

Running the Example

Creating the Notepad Project

Main Source File

Designing a UI

Using Qt Widgets Designer

Notepad Header File

Notepad Source File

Project File

Adding User Interaction

Opening a file

Saving a file

Saving a file under another name

Printing a File

Select a Font

Copy, Cut, Paste, Undo, and Redo

Building and Running from the Command Line

Gradients

Graphics View Examples

Graphicsview Examples

Graphics View Framework

Graphics View

GraphicsView

Graphics

Canvas

The Graphics View Architecture

The Scene

The View

The Item

Classes in the Graphics View Framework

The Graphics View Coordinate System

Item Coordinates

Scene Coordinates

View Coordinates

Coordinate Mapping

Key Features

Zooming and rotating

Printing

Drag and Drop

Cursors and Tooltips

Animation

OpenGL Rendering

Item Groups

Widgets and Layouts

QGraphicsWidget

QGraphicsLayout

Embedded Widget Support

Performance

Floating Point Instructions

Image Composition Example

Setting Up The Resource File

ImageComposer Class Definition

ImageComposer Class Implementation

The main() Function

Image Gestures Example

ImageWidget Class Definition

ImageWidget Class Implementation

Keyboard Focus in Widgets

keyboard focus

Focus Motion

Tab or Shift+Tab

The User Clicks a Widget

The User Presses a Keyboard Shortcut

The User Rotates the Mouse Wheel

The User Moves the Focus to This Window

Layout Management

stretch factor

Introduction

Qt's Layout Classes

Horizontal, Vertical, Grid, and Form Layouts

Laying Out Widgets in Code

Tips for Using Layouts

Adding Widgets to a Layout

Stretch Factors

Custom Widgets in Layouts

Layout Issues

Manual Layout

How to Write A Custom Layout Manager

The Header File (card<@op>.</@op>h)

The Implementation File (card<@op>.</@op>cpp)

Further Notes

Layout Examples

License Wizard Example

The LicenseWizard Class

The IntroPage Class

The EvaluatePage Class

The ConclusionPage Class

Line Edits Example

Window Class Definition

Window Class Implementation

Menus Example

MainWindow Class Definition

MainWindow Class Implementation

Model/View Programming

EditingHints

Model/View Classes

Introduction to Model/View Programming

The model/view architecture

Models

Views

Delegates

Sorting

Convenience classes

Using Models and Views

Two models included in Qt

Using views with an existing model

Model Classes

Basic concepts

Model indexes

Rows and columns

Parents of items

Item roles

Summary

Using model indexes

Further reading

View Classes

Concepts

Using an existing view

Using a model

Using multiple views of a model

Handling selections of items

Sharing selections among views

Delegate Classes

Concepts

Using an existing delegate

A simple delegate

Providing an editor

Submitting data to the model

Updating the editor's geometry

Editing hints

Handling Selections in Item Views

Concepts

Current item and selected items

Using a selection model

Selecting items

Reading the selection state

Updating a selection

Selecting all items in a model

Creating New Models

Designing a model

A read-only example model

Dimensions of the model

Model headers and data

An editable model

Making the model editable

Inserting and removing rows

Next steps

Item View Convenience Classes

List widgets

Tree widgets

Table widgets

Common features

Hidden items

Selections

Searching

Using Drag and Drop with Item Views

Using convenience views

Using model/view classes

Enabling drag and drop for items

Encoding exported data

Inserting dropped data into a model

Decoding imported data

Proxy Models

Using proxy models

Customizing proxy models

Custom filtering models

Custom sorting models

Model Subclassing Reference

Item data handling

Read-Only access

Editable items

Resizable models

Lazy population of model data

Navigation and model index creation

Parents and children

Drag and drop support and MIME type handling

MIME data

Accepting dropped data

Convenience views

Performance optimization for large amounts of data

The Model/View Classes

Related Examples

Model/View Tutorial

1. Introduction

1.1 Standard Widgets

1.2 Model/View to the Rescue

1.3 Overview of the Model/View Widgets

1.4 Using Adapters between Forms and Models

2. A Simple Model/View Application

2.1 A Read Only Table

2.2 Extending the Read Only Example with Roles

2.3 A Clock inside a Table Cell

2.4 Setting up Headers for Columns and Rows

2.5 The Minimal Editing Example

3. Intermediate Topics

3.1 TreeView

3.2 Working with Selections

3.3 Predefined Models

3.4 Delegates

3.5 Debugging with ModelTest

4. Good Sources of Additional Information

4.1 Books

4.2 Qt Documentation

Order Form Example

DetailsDialog Definition

DetailsDialog Implementation

MainWindow Definition

MainWindow Implementation

main() Function

Painter Paths Example

Window Class Definition

Window Class Implementation

RenderArea Class Definition

RenderArea Class Implementation

Path Stroking

Display Features

Editing Features

Signals

Model/View Framework

Basic Usage

Iterating Through Completions

The Completion Model

Handling Tree Models

Using a Pop-up Calendar Widget

Keyboard Tracking

Modal Dialogs

Modeless Dialogs

Default Button

Escape Key

Extensibility

Return Value (Modal Dialogs)

Code Examples

Appearance

Gesture Properties

Lifecycle of a Gesture Object

Further Reading

Recognizing Gestures

Supporting New Gestures

Size Hints and Size Policies in an Anchor Layout

Spacing within an Anchor Layout

Known Issues

Size Hints and Size Policies in QGraphicsGridLayout

Transformations

Painting

Sorting

Events

Custom Data

Writing a Custom Layout

Activating the Layout

Activating the Layout Implicitly

Event Handling

Margin Handling

Subclassing QGraphicsLayoutItem

Nesting QGraphicsLayoutItems

Size Hints and Size Policies in QGraphicsLinearLayout

Spacing within QGraphicsLinearLayout

Stretch Factor in QGraphicsLinearLayout

QGraphicsLinearLayout Compared to Other Layouts

Parents and Children

Embedding a Widget with QGraphicsProxyWidget

Synchronizing Widget States

Event Handling and Propagation

Moving Header Sections

Appearance

Standard Roles and Data Types

Subclassing

QStyledItemDelegate vs. QItemDelegate

Standard Editing Widgets

Constraining Text

Editing Text

Setting a Frame

Default Key Bindings

Improving Performance

Subclassing

Qt Main Window Framework

Creating Main Window Components

Creating Menus

Creating Toolbars

Creating Dock Widgets

The Status Bar

Storing State

Subwindow Handling

Actions

QMenu on macOS with Qt Build Against Cocoa

Usage

Platform Dependent Look and Feel

QMenuBar as a Global Menu Bar

Examples

The Property-based API

Rich Text and the Text Format Property

Severity Levels and the Icon and Pixmap Properties

The Static Functions API

Advanced Usage

Default and Escape Keys

Introduction and Concepts

Using QPlainTextEdit as a Display Widget

Read-only Key Bindings

Using QPlainTextEdit as an Editor

Syntax Highlighting

Editing Key Bindings

Differences to QTextEdit

QRegularExpression Example

Size Hints and Layouts

Subclassing QSpinBox

permanent message

Setting a Style

Developing Style-Aware Custom Widgets

Creating a Custom Style

Using a Custom Style

Right-to-Left Desktops

Styles in Item Views

Subclassing QStyledItemDelegate

QStyledItemDelegate vs. QItemDelegate

Navigation

Visual Appearance

Coordinate Systems

Subclassing

Document Source and Contents

Navigation

Introduction and Concepts

Using QTextEdit as a Display Widget

Read-only Key Bindings

Using QTextEdit as an Editor

Drag and Drop

Editing Key Bindings

Key Bindings

Improving Performance

Subclassing

Top-Level and Child Widgets

Composite Widgets

Custom Widgets and Painting

Size Hints and Size Policies

Events

Groups of Functions and Properties

Widget Style Sheets

Transparency and Double Buffering

Creating Translucent Windows

Native Widgets vs Alien Widgets

field mechanism

initialize page

mandatory fields

A Trivial Example

Wizard Look and Feel

Elements of a Wizard Page

Registering and Using Fields

Creating Linear Wizards

Creating Non-Linear Wizards

Qt Style Sheets

style sheet

Overview

Qt Style Sheets Examples

Style Sheet Usage

Customizing the Foreground and Background Colors

Customizing Using Dynamic Properties

Customizing a QPushButton Using the Box Model

Customizing the QPushButton's Menu Indicator Sub-Control

Complex Selector Example

Customizing Specific Widgets

Customizing QAbstractScrollArea

Customizing QCheckBox

Customizing QComboBox

Customizing QDockWidget

Customizing QFrame

Customizing QGroupBox

Customizing QHeaderView

Customizing QLineEdit

Customizing QListView

Customizing QMainWindow

Customizing QMenu

Customizing QMenuBar

Customizing QProgressBar

Customizing QPushButton

Customizing QRadioButton

Customizing QScrollBar

Customizing QSizeGrip

Customizing QSlider

Customizing QSpinBox

Customizing QSplitter

Customizing QStatusBar

Customizing QTabWidget and QTabBar

Customizing QTableView

Customizing QToolBar

Customizing QToolBox

Customizing QToolButton

Customizing QToolTip

Customizing QTreeView

Common Mistakes

QPushButton and images

Qt Style Sheets Reference

list of icons

Alignment

Attachment

Background

Boolean

Border

Border Image

Border Style

Box Colors

Box Lengths

Brush

Color

Font

Font Size

Font Style

Font Weight

Gradient

Icon

Length

Number

Origin

PaletteRole

Radius

Repeat

Url

List of Stylable Widgets

List of Properties

accent-color

alternate-background-color

background

background-color

background-image

background-repeat

background-position

background-attachment

background-clip

background-origin

border

border-top

border-right

border-bottom

border-left

border-color

border-top-color

border-right-color

border-bottom-color

border-left-color

border-image

border-radius

border-top-left-radius

border-top-right-radius

border-bottom-right-radius

border-bottom-left-radius

border-style

border-top-style

border-right-style

border-bottom-style

border-left-style

border-width

border-top-width

border-right-width

border-bottom-width

border-left-width

bottom

button-layout

color

dialogbuttonbox-buttons-have-icons

font

font-family

font-size

font-style

font-weight

gridline-color*

height

icon

icon-size

image*

image-position

left

lineedit-password-character*

lineedit-password-mask-delay*

margin

margin-top

margin-right

margin-bottom

margin-left

max-height

max-width

messagebox-text-interaction-flags*

min-height

min-width

opacity*

outline

outline-color

outline-offset

outline-style

outline-radius

outline-bottom-left-radius

outline-bottom-right-radius

outline-top-left-radius

outline-top-right-radius

padding

padding-top

padding-right

padding-bottom

padding-left

paint-alternating-row-colors-for-empty-area

placeholder-text-color*

position

right

selection-background-color*

selection-color*

show-decoration-selected*

spacing*

subcontrol-origin*

subcontrol-position*

titlebar-show-tooltips-on-buttons

widget-animation-duration*

text-align

text-decoration

top

width

-qt-background-role

-qt-style-features

List of Icons

List of Property Types

List of Pseudo-States

List of Sub-Controls

Qt Widget Gallery

Qt Widgets

Widgets

Styles

Layouts

Model/View Classes

Graphics View

Using the Module

Building with CMake

Building with qmake

Articles and Guides

Examples

API Reference

Module Evolution

Licenses

Qt Widgets Designer Integration

Scribble Example

ScribbleArea Class Definition

ScribbleArea Class Implementation

MainWindow Class Definition

MainWindow Class Implementation

Shortcut Editor Example

Design and Concepts

ShortcutEditorModelItem Class Definition

ShortcutEditorModel Class Definition

ShortcutEditorModel Class Implementation

Setting Up the Data in the Model

Simple Anchor Layout Example

Simple RHI Widget Example

Structure and main()

Rendering Setup

Rendering

Simple Tree Model Example

SimpleTreeModelStructure

Design and Concepts

TreeItem Class Definition

TreeItem Class Implementation

TreeModel Class Definition

TreeModel Class Implementation

Setting Up the Data in the Model

Testing the model

Sinclair Spectrum

Sliders Example

Window Class Definition

Window Class Implementation

SlidersGroup Class Definition

SlidersGroup Class Implementation

Spin Boxes Example

Window Class Definition

Window Class Implementation

Spreadsheet

Standard Dialogs Example

Star Delegate Example

StarDelegate Class Definition

StarDelegate Class Implementation

StarEditor Class Definition

StarEditor Class Implementation

StarRating Class Definition

StarRating Class Implementation

The main() Function

Possible Extensions and Suggestions

Styles and Style Aware Widgets

Customizing a Style

Implementing a Custom Style

Classes for Widget Styling

The QStyle Implementation

The Style Elements

Primitive Elements

Control Elements

Complex Control Elements

Other QStyle Tasks

Style Options

QStyle Functions

The Palette

Implementation Issues

Java Style

Design and Implementation

Limitations and Differences from Java

Styling Java Check Boxes

Widget Walkthrough

Common Widget Properties

Widget Reference

Push Buttons

Check and Radio Buttons

Tabs

Scroll Bars

Sliders

Spin Boxes

Title Bar

Combo Box

Group Boxes

Splitters

Progress Bar

Tool Buttons

Toolbars

Menus

Menu Bar

Item View Headers

Tree Branch Indicators

Tool Boxes

Size Grip

Rubber Band

Dock Widgets

Styling

Syntax Highlighter Example

Highlighter Class Definition

Highlighter Class Implementation

MainWindow Class Definition

MainWindow Class Implementation

System Tray Icon Example

Window Class Definition

Window Class Implementation

Tab Dialog Example

TabDialog Class Definition

TabDialog Class Implementation

GeneralTab Class Definition

GeneralTab Class Implementation

PermissionsTab Class Definition

PermissionsTab Class Implementation

ApplicationsTab Class Definition

ApplicationsTab Class Implementation

Tablet Example

MainWindow Class Definition

MainWindow Class Implementation

TabletCanvas Class Definition

TabletCanvas Class Implementation

TabletApplication Class Definition

TabletApplication Class Implementation

The main() function

Taking a Screenshot

Screenshot Class Definition

Screenshot Class Implementation

The Style Sheet Syntax

ID Selector

Style Rules

Selector Types

Sub-Controls

Pseudo-States

Conflict Resolution

Cascading

Inheritance

Widgets Inside C++ Namespaces

Setting QObject Properties

Touch Knobs Example

Transformations Example

Transformation Operations

RenderArea Class Definition

RenderArea Class Implementation

Window Class Definition

Window Class Implementation

Summary

Translucent Background

ShapedClock Class Definition

ShapedClock Class Implementation

Tree Model Completer Example

The Resource File

TreeModelCompleter Class Definition

TreeModelCompleter Class Implementation

MainWindow Class Definition

MainWindow Class Implementation

main() Function

Trivial Wizard Example

Introduction Page

Registration Page

Conclusion Page

main() Function

Undo Framework Example

MainWindow Class Definition

MainWindow Class Implementation

AddCommand Class Definition

AddCommand Class Implementation

DeleteCommand Class Definition

DeleteCommand Class Implementation

MoveCommand Class Definition

MoveCommand Class Implementation

DiagramScene Class Definition

The main() Function

Vector Deformation

Widgets Classes

The Widget Classes

Basic Widget Classes

Advanced Widget Classes

Abstract Widget Classes

Organizer Widget Classes

Graphics View Classes

Model/View Classes

Main Window and Related Classes

Widget Appearance and Style-Related Classes

Layout Classes

Widgets Gallery Example

Widgets Tutorial

Introduction

Writing a Main Function

Simple Widget Examples

Real World Widget Examples

Building The Examples

Widgets Tutorial - Child Widgets

Widgets Tutorial - Creating a Window

Widgets Tutorial - Nested Layouts

Setting up the Model

Widgets Tutorial - Using Layouts

Window Flags Example

ControllerWindow Class Definition

ControllerWindow Class Implementation

PreviewWindow Class Definition

PreviewWindow Class Implementation

Window and Dialog Widgets

window geometry

Primary and Secondary Windows

Main Windows and Dialogs

Window Geometry

X11 Peculiarities

Wayland Peculiarities

main.cpp

qt_add_ui

qt6_add_ui

Synopsis

Description

Arguments

TARGET

SOURCES

INCLUDE_PREFIX

OPTIONS

Examples

Without INCLUDE_PREFIX

With INCLUDE_PREFIX

Multiple .ui files

When to prefer qt_add_ui over AUTOUIC?

When to prefer qt_add_ui over qt_wrap_ui?

qt_wrap_ui

qt6_wrap_ui

Synopsis

Description

Options

Examples

Desktop Examples

Dialog Examples

Item Views Examples

Main Window Examples

Painting Examples

Rich Text Examples

Qt Widgets Examples

Standard Dialogs

Qt Widgets C++ Classes