1

Currently, I'm building a web automation app on Chrome to help me automate some tasks. And in the process of running, if the program encountered errors or finished the work, it would show errors messages or notification. To to that I'm using QmessageBox. But here arises a problem that when I 'm running app and I switch to do some orther works (Ex: watch a movie, ...), the pop up doesn't show on main window and seems to be hidden. And I have to minimize the main window to see it. So I want to find a solution likes options of QmessageBox or something to show pop up on main window. Thank for your helps.

And here is my code

def message(title, info, icon_path='ac_solution.ico'):
    message_box = QtGui.QMessageBox()
    message_box.setText(info)
    message_box.setWindowTitle(title)
    message_box.setWindowIcon(QtGui.QIcon(icon_path))
    message_box.setIconPixmap(QtGui.QPixmap(icon_path))
    message_box.exec_()
leminhnguyen
  • 1,518
  • 2
  • 13
  • 19

1 Answers1

2

What you're probably looking for is window "modality", which means that a window is "modal" to its parent, taking ownership of mouse/keyboard interaction which will not be passed on its parent until the dialog is closed.

It's not clear if your message is a static function or a method of your app or main window, but if you need this kind of behavior, you need a parent.

message_box = QtGui.QMessageBox(parent)

In this way, you'll have a modal message box that will always be in front of the parent (e.g. your main window).

musicamante
  • 41,230
  • 6
  • 33
  • 58
  • Thanks you for answer, message is a method of my app. When I run app, it will take a tab of Chrome and I create new tab to watch a movie. And I want pop up to be showed on the new tab (Which I'm watching movie) – leminhnguyen Jul 19 '19 at 01:44
  • I've not understood how you're developing your app, since I've got no experience in chrome apps, but I'm afraid that you can't make a QDialog (QMesssageBox windows are QDialog descendants) child of a "tab", as a modal parent of a Qt Dialog has to be a top-level window. So, if you can access to the main browser window *within* the Qt framework (as in a QWidget subclass) you just have to set the QMessageBox parent to it, otherwise I sincerely doubt there is any other solution. – musicamante Jul 19 '19 at 03:01