【问题标题】:PyQt5 QPushButton fires more than oncePyQt5 QPushButton 触发不止一次
【发布时间】:2020-05-28 18:22:29
【问题描述】:

在 Python3 PyQt5 中有没有办法获取信号连接到插槽的次数,即:

QPushButton.clicked.connect(foo)

想知道发出信号时会调用多少次槽 (foo)?

我不是在谈论我的代码中的计数器,而是一种从中获取该数字的方法

PyQt5 存储该信息的位置

【问题讨论】:

  • 不,没有办法知道(Qt 的私有 API 也使用该信号)。我想你有一个XY problem
  • XY 问题是询问您尝试的解决方案,而不是您的实际问题。也就是说,您正在尝试解决问题 X,并且您认为解决方案 Y 会起作用,但是当您遇到麻烦时,您不会询问 X,而是询问 Y。
  • 我只是想了解信号槽的工作原理。我在另一个重复的帖子中收到了消息:“不要多次建立联系”
  • 谢谢你!你总是对我很好,有答案和解释。我知道我应该更正我的代码并考虑一下,但这对我来说很难,有时我会因为我的好奇心或注意力/缺陷障碍而走神。一旦我了解了 API 的概念,我就会尝试阅读它。再次感谢您
  • 1) 如果你想使用 Qt,那么你不需要知道 Qt 是如何工作的,就像开车一样,你不需要知道汽车的引擎是如何制造的,但它汽车手册(Qt 文档)就足够了,3)如果您想知道“引擎”,那么您必须查看引擎手册(C++ 源代码和 sip 实现)

标签: python-3.x pyqt5 signals-slots qpushbutton


【解决方案1】:

我会考虑放置一个

print('any message') #like this you are directly notified via the console console or terminal,...

在您将调用的每个方法中,例如:

from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtWidgets import QApplication, QPushButton
import sys
#import other modules

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)


        # Geometry of main window:
        self.setGeometry(200, 200, 300, 400)
        
        # create a Button Btn1
        self.Btn1 = QPushButton('Fire Button :)', self)
        self.Btn1.clicked.connect(self.Fire1)
        self.Btn1.move(0, 0)

        self.Btn2 = QPushButton('2nd Fire_Button :)', self)
        self.Btn2.clicked.connect(self.Fire2)
        self.Btn2.move(130, 0)

    def Fire1(self):
        print('Worked, Fired once!...details(...)')

    def Fire2(self):
        print('It is Working, but he needs to add his code! Thanks')
        self.setStyleSheet('background:rgba(80, 97, 15, 184);')
        self.resize(600, 210)
        pass
app = QApplication(sys.argv)
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec_())

这是我的回答正在帮助您(这很好!),否则请向我们提供更详细的信息或您正在处理的代码示例,以便更好地帮助您...

【讨论】:

  • 感谢您的回答。打印尝试过(在这种情况下不是),但使用 PyQt5 有点慢(或缓冲不知道)。在第一次锁定结束后离开了 PyQt5,现在回到 Biopython 不确定我是否可以访问我的旧 Qt5 试用版。再次感谢
  • @pippo1980 好吧,没什么
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-26
  • 2014-11-17
  • 1970-01-01
  • 2020-03-25
相关资源
最近更新 更多