代码拉取完成,页面将自动刷新
""" code1: Using signal and slot
import sys
from PySide6.QtWidgets import QApplication, QToolButton, QLineEdit
app = QApplication([])
lineEdit = QLineEdit()
button = QToolButton()
button.clicked.connect(lineEdit.clear)
lineEdit.show()
button.show()
app.exec()
"""
""" code2: DIY slot
import sys
from PySide6.QtWidgets import QApplication, QPushButton
from PySide6.QtCore import Slot
@Slot()
def function():
print("The 'function' has been called!")
app = QApplication([])
button = QPushButton("Call function")
button.clicked.connect(function)
button.show()
sys.exit(app.exec())
"""
#""" code3: DIY signal and slot
import sys
from PySide6.QtWidgets import QApplication, QPushButton
from PySide6.QtCore import QObject, Signal, Slot
class Communicate(QObject):
# create two new signals on the fly: one will handle
# int type, the other will handle strings
speak = Signal((float,), (int,), (str,))
def __init__(self, parent=None):
super().__init__(parent)
self.speak[float].connect(self.say_something)
self.speak[int].connect(self.say_something)
self.speak[str].connect(self.say_something)
# define a new slot that receives a C 'int' or a 'str'
# and has 'say_something' as its name
@Slot(float)
@Slot(int)
@Slot(str)
def say_something(self, arg):
if isinstance(arg, float):
print("This is a float:", arg)
elif isinstance(arg, int):
print("This is a number:", arg)
elif isinstance(arg, str):
print("This is a string:", arg)
if __name__ == '__main__':
app = QApplication(sys.argv)
someone = Communicate()
# emit 'speak' signal with diff argments.
# we have to specify the str as int is the default
someone.speak[float].emit(10.2)
someone.speak[int].emit(10.2)
someone.speak[str].emit("Hello everyone!")
#"""
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。