PyQt无模式对话框不会显示

时间:2017-11-02 22:11:45

标签: python pyqt pyqt4 pyqt5

我希望在等待另一个进程收到消息时显示一个弹出对话框。我不希望这会阻止代码,因此使用.exec_()似乎不太理想。当我调用show .show()时,对话框根本不会弹出。有趣的是,它会显示我是否在它被调用之前使用调试器但是如果我在它之后等待一段时间后仍然没有显示任何内容。这是我的PyQt代码:

from PyQt5.QtWidgets import QApplication, QDialog, QLabel


class Main(QApplication):
   def __init__(self, *args):
       super().__init__([])
       self.popup = Popup()

   def show_popup(self, msg):
       self.popup.set_msg(msg)
       self.popup.show()


class Popup(QDialog):
   def __init__(self):
       super().__init__()
       self.label = QLabel(self)

   def set_msg(self, msg):
       self.label.setText(msg)

在我调用它的过程中,我基本上实例化Main对象并在发送消息后调用show_popup,等待更改文本并在收到响应时关闭。使用exec_()显示弹出窗口,但它会阻止代码在其他进程中运行。非常感谢任何帮助,谢谢。

1 个答案:

答案 0 :(得分:1)

class Popup(QMainWindow):
def __init__(self):
   super().__init__()
   self.setWindowFlags(self.windowFlags() | Qt.Tool |Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)

   self.label = QLabel(self)

def set_msg(self, msg):
   self.label.setText(msg)

我遇到QMessageBox和QWidget的问题,但是继承自QMainWindows,它可以正常工作。

相关问题