0

I want to hide the app icon from taskbar, and find this answer.
Hide PyQt app from taskbar
But I get a new problem.

class MainWindow(QMainWindow):

    update_signal = Signal(str)

    def __init__(self):
        super().__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.setWindowFlags(Qt.WindowStaysOnTopHint
                            | Qt.FramelessWindowHint
                            | Qt.Tool
                            )
        self.setAttribute(Qt.WA_TranslucentBackground, True)
        self.update_signal.connect(self.update_ui)
        t = threading.Thread(target=self.monite_message, daemon=True)
        t.start()

    ...

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.oldPos = event.globalPos()
        if event.button() == Qt.RightButton:
            menu = QMenu(self)

            config_action = menu.addAction('Config')
            quit_action = menu.addAction('Quit')

            action = menu.exec_(self.mapToGlobal(event.pos()))

            if action == quit_action:
                QCoreApplication.quit()
            if action == config_action:
                self.config_form = ConfigForm()
                self.config_form.show()

After setting Qt.Tool parameter, if I open the config window(sub window), when I close config window, the main window has been closed too.

  • Try calling `self.show()` at the end of the menu part. If that's not enough, try delaying it with `QTimer.singleShot(0, self.show)` (eventually use higher values than 0, remember that those are milliseconds). – musicamante Aug 17 '22 at 09:04
  • I have tried these two ways, but no one can fix the problem. Thanks. – SuiFengPiaoYang Aug 17 '22 at 12:42
  • What OS are you using? Be aware that there are *a lot* of [window flags](https://doc.qt.io/qt-5/qt.html#WindowType-enum), and the one you're using (`Tool`) implies some aspects related to mouse events, so, while it might provide the "expected" result at first, it could not be the *correct* one for your needs. I suggest to try different combinations, starting with `Qt.BypassWindowManagerHint`. – musicamante Aug 17 '22 at 14:29
  • Windows. OK, I will read the qt doc and try another one. – SuiFengPiaoYang Aug 18 '22 at 02:06
  • [Qt Hide Taskbar Item](https://stackoverflow.com/questions/4055506/qt-hide-taskbar-item#answer-4056292) I find that this answer can fix the problem. – SuiFengPiaoYang Aug 18 '22 at 12:53
  • Fix how? Are you referring to the flag or the `quitOnLastWindowClosed` property? – musicamante Aug 18 '22 at 13:27
  • `app = QApplication(sys.argv)` `app.setQuitOnLastWindowClosed(False)` – SuiFengPiaoYang Aug 22 '22 at 03:20
  • So in reality your program closed? You never told us that. – musicamante Aug 22 '22 at 11:13

0 Answers0