Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the window title in pyside?

Tags:

python

pyside

I have read the documentation on the following matter, but Qt is so overwhelmingly complex I might have missed the piece.

I have created a QMainWindow and set a title using self.setWindowTitle. Later in the code I want to simply change this title and so I used the method self.setWindowTitle again. But this only removed the title from my application, but put the correct title on the panel in 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'.

My pyside Qt example now removes the title from the application window and puts it instead on the upper hand panel.

Do I need a different method other than setWindowTitle to change the title? Maybe from the centralWidget, or MenuBar, or some other element? 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):

After first setWindowTitle

Ubuntu screenshot after second call of setWindowTitle - the title is not set on the application window itself, but on the very top panel:

After second setWindowTitle

like image 361
Alex Avatar asked May 25 '14 09:05

Alex


People also ask

What is PySide2?

PySide2 is the official Python module from the Qt for Python project, which provides access to the complete Qt 5.12+ framework. The Qt for Python project is developed in the open, with all facilities you'd expect from any modern OSS project such as all code in a git repository and an open design process.


1 Answers

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/

like image 152
Valeriy Gaydar Avatar answered Sep 21 '22 09:09

Valeriy Gaydar