当前位置:网站首页>Qtoolbutton - menu and popup mode
Qtoolbutton - menu and popup mode
2022-07-03 22:41:00 【。 Seventy two.】
1、 Menu and popup mode , Same as QPushButton, Click to have a quick access .
During the setting process , The top-level menu will not pop up the title and related icons .
2、 Set menu options for normal buttons , During the setting process , The top-level menu will not pop up the title and related icons .
import sys
from PyQt5.Qt import *
# Make it into an activity module , Easy to modify
# 1、 Create application , You can pass parameters to app, Enter parameters from the command line
app = QApplication(sys.argv)
window = QWidget()
window.setWindowTitle("QToolButton Use ")
window.resize(500, 500)
# Create a normal button
btn = QPushButton(window)
btn.setText(" General buttons ")
btn.move(100, 100)
btn.setFlat(True)
menu = QMenu(btn)
menu.setTitle(" menu ")
# Put submenus and actions in the menu
sub_menu = QMenu(menu)
sub_menu.setTitle(" Sub menu ")
# Put in meun In parent object
action = QAction(" Behavior ", menu)
# monitor action Signal in
action.triggered.connect(lambda : print(" Clicked behavior "))
menu.addMenu(sub_menu)
menu.addSeparator()
menu.addAction(action)
btn.setMenu(menu)
window.show()
sys.exit(app.exec_())
3、 Set common tool buttons :(setMenu() call QToolButton Class )
How to pop up menus under ordinary tool buttons :( Hold down the mouse , It will appear later .)
Use scenarios : This button of the browser , Press and hold and the browsing record will be displayed .
import sys
from PyQt5.Qt import *
# Make it into an activity module , Easy to modify
# 1、 Create application , You can pass parameters to app, Enter parameters from the command line
app = QApplication(sys.argv)
window = QWidget()
window.setWindowTitle("QToolButton Use ")
window.resize(500, 500)
tb = QToolButton(window)
tb.setText(" Button ")
tb.setArrowType(Qt.LeftArrow)
tb.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
tb.setAutoRaise(True)
menu = QMenu(tb)
menu.setTitle(" menu ")
# Put submenus and actions in the menu
sub_menu = QMenu(menu)
sub_menu.setTitle(" Sub menu ")
# Put in meun In parent object
action = QAction(" Behavior ", menu)
# monitor action Signal in
action.triggered.connect(lambda : print(" Clicked behavior "))
menu.addMenu(sub_menu)
menu.addSeparator()
menu.addAction(action)
tb.setMenu(menu)
window.show()
sys.exit(app.exec_())
4、 Modify the menu popup mode of the tool button :
Menu mode details : Sometimes the image signal is transmitted .( The slot to which this signal is connected is not executed )
import sys
from PyQt5.Qt import *
# Make it into an activity module , Easy to modify
# 1、 Create application , You can pass parameters to app, Enter parameters from the command line
app = QApplication(sys.argv)
window = QWidget()
window.setWindowTitle("QToolButton Use ")
window.resize(500, 500)
tb = QToolButton(window)
tb.setText(" Button ")
tb.setArrowType(Qt.LeftArrow)
tb.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
tb.setAutoRaise(True)
menu = QMenu(tb)
menu.setTitle(" menu ")
# Put submenus and actions in the menu
sub_menu = QMenu(menu)
sub_menu.setTitle(" Sub menu ")
# Put in meun In parent object
action = QAction(" Behavior ", menu)
# monitor action Signal in
action.triggered.connect(lambda : print(" Clicked behavior "))
menu.addMenu(sub_menu)
menu.addSeparator()
menu.addAction(action)
tb.clicked.connect(lambda: print(" The tool button is clicked "))
tb.setMenu(menu)
# Modify the popup method of the menu
#tb.setPopupMode(QToolButton.InstantPopup)
window.show()
sys.exit(app.exec_())
边栏推荐
- How to restore the factory settings of HP computer
- [flax high frequency question] leetcode 426 Convert binary search tree to sorted double linked list
- In 2022, 6G development has indeed warmed up
- Programming language (2)
- 油猴插件
- . Net ADO splicing SQL statement with parameters
- MLX90614 driver, function introduction and PEC verification
- Programming language (1)
- [template summary] - binary search tree BST - Basics
- [sg function] lightoj Partitioning Game
猜你喜欢
The latest analysis of crane driver (limited to bridge crane) in 2022 and the test questions and analysis of crane driver (limited to bridge crane)
pivot ROP Emporium
How to connect a laptop to a projector
Blue Bridge Cup -- Mason prime
Sort merge sort
How to solve the problem of computer networking but showing no Internet connection
Awk getting started to proficient series - awk quick start
[actual combat record] record the whole process of the server being attacked (redis vulnerability)
How to solve the problem of requiring a password when accessing your network neighborhood on your computer
Es6~es12 knowledge sorting and summary
随机推荐
Harbor integrated LDAP authentication
Yyds dry goods inventory Prometheus alarm Art
[Android reverse] use the DB browser to view and modify the SQLite database (copy the database file from the Android application data directory | use the DB browser tool to view the data block file)
Programming language (1)
Bluebridge cup Guoxin Changtian single chip microcomputer -- hardware environment (I)
Mongoose the table associated with the primary key, and automatically bring out the data of another table
2022 electrician (elementary) examination questions and electrician (elementary) registration examination
Bluebridge cup Guoxin Changtian single chip microcomputer -- detailed explanation of schematic diagram (IV)
[sg function]split game (2020 Jiangxi university student programming competition)
[sg function] 2021 Niuke winter vacation training camp 6 h. winter messenger 2
Pan Yueming helps Germany's Rochester Zodiac custom wristwatch
Flutter internationalized Intl
Runtime. getRuntime(). totalMemory/maxMemory()
SDMU OJ#P19. Stock trading
Format cluster and start cluster
Pat grade A - 1164 good in C (20 points)
string
Learning notes of raspberry pie 4B - IO communication (SPI)
The latest analysis of R1 quick opening pressure vessel operation in 2022 and the examination question bank of R1 quick opening pressure vessel operation
How to solve win10 black screen with only mouse arrow