标签云

微信群

扫码加入我们

WeChat QR Code

I have a PyQt application that has a main window and a number of dialogs, some modal, some not. The app is cross-platform, but this particular issue is specific to Windows.If the dialog is not parented (modal or not), it has its own taskbar entry under the same group as the main window, but the taskbar title is always "python". Calling setWindowTitle() behaves as expected on the main window, but only affects the title bar for other dialogs. I've played around with window flags, and looked for low-level, Windows-specific approaches via PyWin32, but no luck thus far.Is there anything else I can do to modify the taskbar title for the unparented dialogs?(sidenote: if I parent my non-modal dialogs, the taskbar is a non-issue, but those dialogs are always on top of the main window, which is undesirable)(sidenote 2: due to external dependencies, I am limited to Qt 4.5.3 and PyQt 4.5.4 for now)Below is some sample code that exhibits the problem. It's a simple QMainWindow with buttons to pop up dialogs. The main window shows as "Main Window" in the taskbar. If I click the "Open Unparented Dialog" button, the title "Unparented" appears properly in the dialog's title bar, but the task bar says "python".import sysfrom PyQt4 import QtCore, QtGuimainWindow = Nonedef openDialog(parent):global mainWindowdialog = QtGui.QDialog(parent)layout = QtGui.QVBoxLayout()buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Cancel)buttonBox.rejected.connect(dialog.reject)layout.addWidget(buttonBox)dialog.setLayout(layout)dialog.setWindowTitle('Parented' if parent is not None else 'Unparented')dialog.exec_()def openUnparentedDialog():openDialog(None)def openParentedDialog():openDialog(mainWindow)def main():global mainWindowapp = QtGui.QApplication(sys.argv)mainWindow = QtGui.QMainWindow()mainWidget = QtGui.QWidget()mainWindow.setCentralWidget(mainWidget)layout = QtGui.QVBoxLayout()mainWidget.setLayout(layout)button1 = QtGui.QPushButton('Open Unparented Dialog')button1.clicked.connect(openUnparentedDialog)layout.addWidget(button1)button2 = QtGui.QPushButton('Open Parented Dialog')button2.clicked.connect(openParentedDialog)layout.addWidget(button2)mainWindow.setWindowTitle('Main Window')mainWindow.show()app.exec_()if __name__ == '__main__':main()


I tested with PyQt 4.5.4 and Qt 4.5.2, and setWindowTitle can set correctly two different titles in the taskbar for the QDialog and the QMainWindow without changing any flag or attribute.

2019年05月24日16分42秒

Sorry, I missed the notification for this. I've added some sample code above to illustrate the problem, using setWindowTitle on a QMainWindow and a QDialog. Does the above code correctly set the taskbar for you?

2019年05月24日16分42秒

Aha! I may be trying to solve the wrong problem. The task bar does get set appropriately. However, when the taskbar entries stack (because of several open applications), the display is "python", presumably as the root executable.

2019年05月23日16分42秒