当前位置:网站首页>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_())
边栏推荐
- Hcip day 16 notes
- Hcip day 14 notes
- Bluebridge cup Guoxin Changtian single chip microcomputer -- detailed explanation of schematic diagram (IV)
- MLX90614 driver, function introduction and PEC verification
- LeetCode 1646. Get the maximum value in the generated array
- Unique in China! Alibaba cloud container service enters the Forrester leader quadrant
- 2022 free examination questions for safety management personnel of hazardous chemical business units and reexamination examination for safety management personnel of hazardous chemical business units
- Blue Bridge Cup Guoxin Changtian single chip microcomputer -- software environment (II)
- On my first day at work, this API timeout optimization put me down!
- Exness: the Central Bank of England will raise interest rates again in March, and inflation is coming
猜你喜欢

BUUCTF,Misc:LSB

This time, thoroughly understand bidirectional data binding 01

Es6~es12 knowledge sorting and summary

Awk getting started to proficient series - awk quick start

540. Single element in ordered array

Code in keil5 -- use the code formatting tool astyle (plug-in)

How can enterprises and developers take advantage of the explosion of cloud native landing?

QGIS grid processing DEM data reclassification

Pointer concept & character pointer & pointer array yyds dry inventory

Buuctf, misc: sniffed traffic
随机推荐
How does sentinel, a traffic management artifact, make it easy for business parties to access?
Label coco format data and format data in the upper left corner and lower right corner are mutually converted
Unique in China! Alibaba cloud container service enters the Forrester leader quadrant
[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)
Weekly leetcode - nc9/nc56/nc89/nc126/nc69/nc120
[automation operation and maintenance novice village] flask-2 certification
Leetcode: a single element in an ordered array
LeetCode 540. A single element in an ordered array
IDENTITY
IPhone development swift foundation 09 assets
Meta metauniverse female safety problems occur frequently, how to solve the relevant problems in the metauniverse?
Pooling idea: string constant pool, thread pool, database connection pool
The difference between SRAM and DRAM
[untitled]
Exclusive download! Alibaba cloud native brings 10 + technical experts to bring "new possibilities of cloud native and cloud future"
File copy method
Codeforces Round #768 (Div. 1)(A-C)
4 environment construction -standalone ha
Recursion and recursion
What indicators should be paid attention to in current limit monitoring?