简体   繁体   English

如何在pyside中更改窗口标题?

[英]How to change the window title in pyside?

I have read the documentation on the following matter, but Qt is so overwhelmingly complex I might have missed the piece. 我已经阅读了有关以下问题的文档,但是Qt是如此的复杂,以至于我可能错过了。

I have created a QMainWindow and set a title using self.setWindowTitle . 我创建了一个QMainWindow并使用self.setWindowTitle设置了标题。 Later in the code I want to simply change this title and so I used the method self.setWindowTitle again. 稍后在代码中,我只想更改此标题,因此我再次使用了self.setWindowTitle方法。 But this only removed the title from my application, but put the correct title on the panel in Ubuntu. 但这只会从我的应用程序中删除标题,而是将正确的标题放在Ubuntu的面板上。

Further explanation on an Ubuntu system: For example, When I edit this text in the webbrowser window the title says 'How to change the window...' and on the panel on the top of the computer screen I see the text 'Firefox Web Browser'. 在Ubuntu系统上的进一步说明:例如,当我在webbrowser窗口中编辑此文本时,标题为“如何更改窗口...”,并且在计算机屏幕顶部的面板上看到文本“ Firefox Web”。浏览器”。

My pyside Qt example now removes the title from the application window and puts it instead on the upper hand panel. 我的pyside Qt示例现在从应用程序窗口中删除标题,并将其放在上部面板上。

Do I need a different method other than setWindowTitle to change the title? setWindowTitle ,是否需要其他方法来更改标题? Maybe from the centralWidget, or MenuBar, or some other element? 也许来自centralWidget,MenuBar或其他元素? And why did the title vanish in the first place? 为什么标题一开始就消失了?

Ubuntu screenshot after first call of setWindowTitle -the title 'PicSel' is set on the application window title and on the top Ubuntu panel (or whatever this is called): 在首次调用setWindowTitle之后,Ubuntu屏幕截图-在应用程序窗口标题和顶部Ubuntu面板(或任何被称为此名称)上设置了标题“ PicSel”:

第一次setWindowTitle之后

Ubuntu screenshot after second call of setWindowTitle - the title is not set on the application window itself, but on the very top panel: 第二次调用setWindowTitle后的Ubuntu屏幕快照-标题不是在应用程序窗口本身上设置的,而是在最上面的面板上设置的:

第二个setWindowTitle之后

import sys
from PySide import QtGui, QtCore

class Example(QtGui.QWidget):

    def __init__(self):
        super(Example, self).__init__()

        self.initUI()

    def initUI(self):      

        cb = QtGui.QCheckBox('Show title', self)
        cb.move(20, 20)
        cb.toggle()
        cb.stateChanged.connect(self.changeTitle)

        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle('QtGui.QCheckBox')
        self.show()

    def changeTitle(self, state):

        if state == QtCore.Qt.Checked:
            self.setWindowTitle('Checkbox')
        else:
            self.setWindowTitle('')

def main():

    app = QtGui.QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

Source: http://zetcode.com/gui/pysidetutorial/widgets/ 来源:http: //zetcode.com/gui/pysidetutorial/widgets/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM