PyQt5 子窗口鼠标事件失效的问题
我想通过点击一个按钮弹出一个对话框,然后点击对话框上的一个按钮可以显示数据,单独的对话框在点击的时候会发生鼠标事件,得到我想要的结果,但是当我把两个窗口连接起来,对话框能正常弹出,但是我点击鼠标却没有反应了,经调试发现单独对话框点击鼠标能触发鼠标事件,而关联了主窗口后子窗口点击鼠标无法触发事件,请问这是什么原因?该如何解决?
#这是我的主窗口调用的弹出对话框的函数
def accept(self):
self.dialog = QDialog()
ui = supply_dialog.Supply_Dialog()
ui.setupUi(self.dialog)
self.dialog.show()
#以下是我对话框部分的程序
from PyQt5 import QtCore, QtGui, QtWidgets
import test_MySQL
class Supply_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(640, 480)
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(480, 330, 71, 41))
font = QtGui.QFont()
font.setFamily("Jokerman")
self.pushButton.setFont(font)
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(40, 0, 81, 31))
font = QtGui.QFont()
font.setFamily("MV Boli")
font.setPointSize(12)
self.label.setFont(font)
self.label.setObjectName("label")
self.tableWidget = QtWidgets.QTableWidget(Dialog)
self.tableWidget.setGeometry(QtCore.QRect(30, 40, 581, 271))
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(9)
self.tableWidget.setRowCount(0)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(2, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(3, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(4, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(5, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(6, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(7, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(8, item)
self.retranslateUi(Dialog)
self.pushButton.clicked['bool'].connect(self.accept_test)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.pushButton.setText(_translate("Dialog", "查询"))
self.label.setText(_translate("Dialog", "供应商表"))
item = self.tableWidget.horizontalHeaderItem(0)
item.setText(_translate("Dialog", "Pronum"))
item = self.tableWidget.horizontalHeaderItem(1)
item.setText(_translate("Dialog", "Supnum"))
item = self.tableWidget.horizontalHeaderItem(2)
item.setText(_translate("Dialog", "Supname"))
item = self.tableWidget.horizontalHeaderItem(3)
item.setText(_translate("Dialog", "Suplinkman"))
item = self.tableWidget.horizontalHeaderItem(4)
item.setText(_translate("Dialog", "Tel"))
item = self.tableWidget.horizontalHeaderItem(5)
item.setText(_translate("Dialog", "Supaddr"))
item = self.tableWidget.horizontalHeaderItem(6)
item.setText(_translate("Dialog", "email"))
item = self.tableWidget.horizontalHeaderItem(7)
item.setText(_translate("Dialog", "QQ"))
item = self.tableWidget.horizontalHeaderItem(8)
item.setText(_translate("Dialog", "URL"))
def accept_test(self):
supply = test_MySQL.MySQL()
result = supply.fecth_date()
supply.conn.commit()
supply.conn.close()
self.tableWidget.setRowCount(len(result))
for i in range(0, len(result)):
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setVerticalHeaderItem(i, item)
for i in range(0, len(result)):
for j in range(0, 9):
self.tableWidget.setItem(i, j, QtWidgets.QTableWidgetItem(result[i][j]))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论