pyqt5对话框self.close()不要停止
我是Python和Pyqt的新手。 我有一个带有MainWindow的应用程序和一个对话框(设置窗口)。在对话框类(加载UIC.loadui)中,我有一个段循环来进行一些OPENCV图像检测。当我调用对话框关闭时,请循环仍在运行。我该如何停止它? 谢谢 这是代码提取物,全部都在一个文件中:
class UI(QMainWindow):
def __init__(self):
super(UI, self).__init__()
#xxxxxx MORE CODE xxxxx
uic.loadUi("BTS.ui", self)
self.action_Open_Settings.triggered.connect(lambda: self.open_settings_window('BAS'))
self.show()
def open_settings_window(self, target):
# Open Settings Window
s_window = SettingsWindow(target)
s_window.exec()
class SettingsWindow(QDialog):
def __init__(self, target):
super(SettingsWindow,self).__init__()
uic.loadUi('set.ui', self)
# Settings Windows named SettingsWindow
self.setWindowTitle(target)
# Load Settings
if target == 'BAS':
self.H_MIN = B_H_MIN
self.H_MAX = B_H_MAX
self.S_MIN = B_S_MIN
self.S_MAX = B_S_MAX
self.Area_Value_Text.setEnabled(False)
self.Peri_Value_Text.setEnabled(False)
else:
self.H_MIN = R_H_MIN
self.H_MAX = R_H_MAX
self.show()
self.run(target)
def run(self, target):
global gtarget
global CROP_SIZE
ref_image = "./set_ref.jpg"
img = cv2.imread(ref_image)
while True:
print('running')
frame = cv2.resize(img, (1280, 720))
h_min = self.horizontalSlider_Hue_Min.value()
h_max = self.horizontalSlider_Hue_Max.value()
#********MORE CODE*************
if cv2.waitKey(1) & 0xFF == ord('q'):
SettingsWindow.close
break
def closeEvent(self, event):
self.close()
if __name__ == "__main__":
app = QApplication(sys.argv)
UIWindow = UI()
app.exec_()
I am new to python and pyqt.
I have a app with a mainwindow and a dialog (settings window). In the dialog class (loaded with uic.loadUi) I have a while loop to do some opencv image detection. When i call the dialog close the while loop still running. How can I stop it?
Thank you
This is a code extract, and is all in one file:
class UI(QMainWindow):
def __init__(self):
super(UI, self).__init__()
#xxxxxx MORE CODE xxxxx
uic.loadUi("BTS.ui", self)
self.action_Open_Settings.triggered.connect(lambda: self.open_settings_window('BAS'))
self.show()
def open_settings_window(self, target):
# Open Settings Window
s_window = SettingsWindow(target)
s_window.exec()
class SettingsWindow(QDialog):
def __init__(self, target):
super(SettingsWindow,self).__init__()
uic.loadUi('set.ui', self)
# Settings Windows named SettingsWindow
self.setWindowTitle(target)
# Load Settings
if target == 'BAS':
self.H_MIN = B_H_MIN
self.H_MAX = B_H_MAX
self.S_MIN = B_S_MIN
self.S_MAX = B_S_MAX
self.Area_Value_Text.setEnabled(False)
self.Peri_Value_Text.setEnabled(False)
else:
self.H_MIN = R_H_MIN
self.H_MAX = R_H_MAX
self.show()
self.run(target)
def run(self, target):
global gtarget
global CROP_SIZE
ref_image = "./set_ref.jpg"
img = cv2.imread(ref_image)
while True:
print('running')
frame = cv2.resize(img, (1280, 720))
h_min = self.horizontalSlider_Hue_Min.value()
h_max = self.horizontalSlider_Hue_Max.value()
#********MORE CODE*************
if cv2.waitKey(1) & 0xFF == ord('q'):
SettingsWindow.close
break
def closeEvent(self, event):
self.close()
if __name__ == "__main__":
app = QApplication(sys.argv)
UIWindow = UI()
app.exec_()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论