11

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

halfer
  • 19,824
  • 17
  • 99
  • 186
Alex
  • 41,580
  • 88
  • 260
  • 469
  • Could you provide some clarification (or perhaps an image)? I'm not sure if it's just me, but this "But this only removed the title from my application, but put the correct title on the panel in Ubuntu" is not very clear. Could you provide an image of what you mean by the application window title? – estebro May 26 '14 at 04:56
  • It seems that you are changing the title for main window instead of the dialog box. You also need to consider the Multiple Document Interface (MDI) and Single Document Interface (SDI) while programming. – Vinay Jun 10 '14 at 05:50
  • So how can I change the title of the dialog box then? – Alex Jun 10 '14 at 06:20
  • 1
    I just attempted this on a Fedora 15 application I'm developing and it works as expected. Perhaps it's OS specific? – James Mertz Jun 11 '14 at 18:29
  • 2
    Just attempted it too on Ubuntu 14.04, Python 3.4 and PySide 1.2.1 and it works as expected (QMainWindow widget title as well as application title are changing both, nothing disappears). Maybe it has something to do with the custom window decoration you seem to have or it is a bug in your Ubuntu ([Window title-bars missing occasionally in Unity](http://askubuntu.com/questions/134172/window-title-bars-missing-occasionally-in-unity). – NoDataDumpNoContribution Jun 12 '14 at 16:33
  • And, did you manage to solve the question in the meantime? – NoDataDumpNoContribution Jul 10 '14 at 15:22
  • Could it be that your new window title simply does not fit? – mdurant Aug 27 '14 at 18:50
  • A link-only answer (now deleted) offered [this solution](http://qt-project.org/wiki/PySideTutorials_Simple_Dialog), which may help a future reader. – halfer Oct 05 '15 at 22:05

1 Answers1

6
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/

Valeriy Gaydar
  • 500
  • 1
  • 6
  • 26
  • I wonder if you would be willing to add an introductory paragraph to this? I've no particular doubt it does not answer the question, but if you can explain _how_ it answers it, that would be great! – halfer Oct 05 '15 at 22:04