set application name in pyside

血红的双手。 提交于 2019-12-04 05:19:46

问题


I created an Application using Qt Creator/Designer under Windows 8 and Qt 5

it starts as follow

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        #MainWindow.setApplicationName("Facturo-Pro") # this doesn't work
        MainWindow.setWindowIcon(QtGui.QIcon('icons/app.png'))
        MainWindow.setObjectName("MainWindow")
        MainWindow.setMinimumSize(QtCore.QSize(800, 600))
        MainWindow.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedStates))

i want to set the application name which should be shown on the window title and task bar

i tried to use

    QtCore.QCoreApplication.setOrganizationName("Moose Soft")
    QtCore.QCoreApplication.setApplicationName("Facturo-Pro")

or

QtCore.QSettings("my app","my org")

but it didn't work, in task bar and window title i see "python"

i don't want to use setWindowTitle() because i want to use

    MainWindow.setWindowFilePath(self.currentFile)

so i will later just update the FilePath and when editing the it a "*" will be shown on the window title!


回答1:


With Qt5, you can set the applicationDisplayName, which is separate from the main title-bar text.

To show the modification state in the title-bar, you would do this:

    QtWidget.qApp.setApplicationDisplayName('Test')
    ...
    window.setWindowFilePath('/path/to/file.txt')
    window.setWindowModified(True)

and the title-bar would look like this: file.txt* - Test

Alternatively, you can get a little more control of the title-bar text by using a special placeholder when setting the window title:

    window.setWindowTitle('/path/to/file.txt[*]')
    window.setWindowModified(True)

and the title-bar would look like this: /path/to/file.txt* - Test

EDIT:

If you're using Qt4, there will no be applicationDisplayName, so you could try this, instead:

    QtGui.qApp.setApplicationName('Test')
    ...
    window.setWindowTitle(
        '/path/to/file.txt[*] - %s' % QtGui.qApp.applicationName())
    window.setWindowModified(True)

and the title-bar should look like this: /path/to/file.txt* - Test



来源:https://stackoverflow.com/questions/27453436/set-application-name-in-pyside

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!