Qt GUI
At the Beginning of a Project
We have four tools. CentralWiget which is locked, menuBar on the top, mainToolBar,and statusBar at below.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Layouts
Vertical Layout
- 物件是很多個row的
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Horizontal Layout
- 物件是很多個column的
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Grid Layout
- 物件排列成格子狀
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Spacers
用於填充空白
Horizontal Spacer
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Vertical Spacer
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 特性:
- QPushButton is more for "Ok"/"Close" type buttons that contain text with an optional icon.
- should always have text.
- 特性:
- 有圖標顯示圖標(文本默認不顯示),無圖標則顯示文本
- A tool button is meant to be displayed in a grid
- it has smaller default internal margins than a push button.
- should generally have an icon.
- use QButtonGroup to make it work as radio button
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Check Box
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- when it click, it means yes, otherwise is no.
寫一個yes的check box 又寫一個no的check box => 錯!
- QCommandLinkButton繼承自QPushButton,是Vista 引入的新控件。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Item Views (Model-Based)
List View
- if you have two-hundred million elements, then this is a good point to use listview.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
code example
Tree View
- It is similar to a QListView in that it displays a list of items, but with the added ability to display items in a hierarchical manner.
- A QTreeView is useful when you need to display data that has a hierarchical structure, such as a file system or a directory structure.
- A QTreeView is also useful when you need to display large amounts of data that can be sorted and filtered. Because a QTreeView only displays the items that are visible on the screen, it is more memory efficient than a QListView for displaying large datasets.

code example
Table View
- A QTableView is a widget in Qt that is used to display and edit tabular data. It provides a user interface for viewing, editing, and navigating rows and columns of data.
- QTableView provides many features that make it easy to work with tabular data, including support for sorting, filtering, and selecting rows and columns. It also supports custom styling and theming

code example
Column View
- each column represents a level of the hierarchy. The first column represents the root level, the second column represents the children of the selected item in the first column, and so on. The user can select an item in any column, and the children of that item will be displayed in the next column.
- is useful for displaying structured data, such as file directories, and allows users to easily navigate through the data in a hierarchical manner.
- It seems that QColumnView only supports displaying a single column of items. If you want to display multiple columns, you can use a QTreeView instead and customize its appearance to look like a column view.

code example: single column
code example three columns (treeview instead)
Undo View
- You can use the QUndoView widget to display the undo and redo actions and allow the user to navigate through the undo and redo history.
- QUndoView provides an interface for viewing the undo stack and allows the user to navigate the undo and redo history of the stack. It displays a list of the actions that can be undone and redone, along with the current state of the stack. The user can select an action to undo or redo by clicking on it, and can also customize the appearance of the view.
pic
code example
Item Widgts (Item-Based)
- The QListWidget can be used to create simple list views, or it can be customized to display complex items with custom widgets. It also provides support for drag and drop operations, editing of items, and sorting.
- Common use:
- Displaying a list of items that can be selected by the user
- Displaying a list of items with associated icons or images
- Creating a simple file or directory browser
- Implementing a basic chat or messaging interface

example code
Containers
Group Box
Frame
MDI Area
Combo Box
- multiple choice, get current text:
QString str = ui->comboBox->currentText();
- see if it's necessary to use slot.
Font Combo Box
Line Edit
- gettext:
text()
- settext:
setText(text)
- one line only
Text Edit
- gettext:
toPlainText()
- settext:
setText(text)
- multiple lines
- can display images in QTextEdit
- use
<img>
to do it
- if use
pixmap
then use label to do it.
- can't adjust the size of images!
- these work.
Plain Text Edit
- gettext:
toPlainText()
- settext:
setPlainText(text)
- QPlainTextEdit works on paragraphs and characters.
- Qt5's documentation doesn't mention that QPlainTextEdit has setText(QString) like QTextEdit does.
Spin Box
Double Spin Box
Time Edit
Date Edit
Date/Time Edit
Dial
Horizontal Slider
Vertical Slider
Key Sequence Edit
Label
- label is a show text
- QLabel 自己適應 text 的大小
LabelName->adjustSize();
- 讓QLabel能夠自動判斷並換行顯示:
Text Browser
Graphics View
LCD Number
Progress Bar
Horizontal Line
Vertical Line
QWebView