The syntax of pyside2 and pyqt5 is basically the same, you can directly choose the qt book and refer to the pyqt blog to learn.
Main reference blogger 1
label control
The Label control is mainly used to display text that cannot be edited by the user, and to identify objects on the form. label can be set to display text and images
- label display text
-
You can directly write text when adding a label control in qt designer
-
Set display text programmatically
self.label.setText('Hello')
- The label tag can display images in the following two ways:
- Images can be displayed directly through QPixmap. In this way, pictures in a certain format cannot be displayed when trying.
pixmap = QPixmap(path)
window.labelOriginImg.setPixmap(pixmap)
- by conversion
img = cv2.imread(path)
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img_show = QImage(img_rgb.data, img_rgb.shape[1], img_rgb.shape[0], QImage.Format_RGB888)
window.labelOriginImg.setPixmap(QPixmap.fromImage(img_show)) # 设置显示图像的标签
If the image display is distorted, due to the image size
img_show = QImage(img_rgb.data, img_rgb.shape[1], img_rgb.shape[0] * 3, QImage.Format_RGB888) #shape[0] *3
Sometimes the image is too large, you can display the label by scaling the image.
img_show = QImage(img_rgb.data, img_rgb.shape[1], img_rgb.shape[0] * 3, QImage.Format_RGB888)
img_show = img_show.scaled( img_show.width() * 0.5, img_show.height() * 0.5, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
add menu
- Add menu directly on qt.
A menu can be added at the upper left of the window, and press the enter key after the input is complete. If you can’t input Chinese in direct editing of the submenu, you can input English first, and set Chinese in the property editor.
- Set the menu bar and shortcut keys through code
self.toolBar.addAction(QIcon('icons/open.jpg'), '打开') #为菜单设置图标
self.actionOpenImg.setShortcut('ctrl+o') #快捷键设置
By adding a tree control as a directory
and listing it as a directory name, add directories of all levels in the project
Add a vertical menu structure
, you can directly add a button in the blank area as a sub-directory
To achieve switching between different interfaces, you can add a stack
First add a frame, divide the window into several parts, and add a stacked widget to the frame to stack windows.
You can set different signals, add slots to connect to different interfaces, and add different controls on different interfaces to perform corresponding operations.
page1 sets parameters, and page2 performs corresponding processing. The left vertical status bar buttons connect to the two interfaces.