在pyside中设置应用程序名称 [英] set application name in pyside

查看:80
本文介绍了在pyside中设置应用程序名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 8 和 Qt 5 下使用 Qt Creator/Designer 创建了一个应用程序

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

开始如下

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

我尝试使用

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

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

但它不起作用,在任务栏和窗口标题中我看到python"

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

我不想使用 setWindowTitle() 因为我想使用

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!

推荐答案

使用 Qt5,您可以设置 applicationDisplayName,与主标题栏文本分开.

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)

标题栏看起来像这样: file.txt* - Test

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)

标题栏看起来像这样: /path/to/file.txt* - Test

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

编辑:

如果您使用的是 Qt4,则不会有 applicationDisplayName,因此您可以试试这个:

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)

标题栏应如下所示: /path/to/file.txt* - Test

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

这篇关于在pyside中设置应用程序名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆