PyQt4: WindowTitle / Label-Text ändern

Alles rund um die Programmierung mit Qt
Antworten
PepeCyB
Beiträge: 7
Registriert: 19. Februar 2007 20:23

PyQt4: WindowTitle / Label-Text ändern

Beitrag von PepeCyB »

Hallo,

wenn ich

1.) in einem Dialog zum Programmstart den Text eines Labels ändern will, klappt das nicht so, wie gedacht. Es geht nur, wenn ich das innerhalb der setupUi mache.

2.) ich den WindowTitle z. B. als Reaktion auf einen Klick auf einen Button ändern möchte, wird der Titel nicht geändert.

Bei PyQt3 klappte das alles immer... ich schätze, es hat sich was am Konzept mit der Version 4 geändert. Nun suche ich schon wochenlang in der Doku und google fleissig rum, werde aber nicht fündig. Kann jemand helfen?

Dateien des NICHT funktionierenden Programms:

main.py:

Code: Alles auswählen

#!/usr/bin/env python 
# -*- coding: utf-8 -*-

import sys 
from PyQt4 import QtCore, QtGui

from mainform_impl import Mainform_Impl


# create Qt application 
app = QtGui.QApplication(sys.argv)
QtCore.QObject.connect(app,QtCore.SIGNAL("lastWindowClosed()"),app,QtCore.SLOT("quit()"))

# create and show Qt form 
MainWindow = QtGui.QMainWindow()
ui = Mainform_Impl()
ui.setupUi(MainWindow)
MainWindow.show()

# enter Qt event-handling loop 
sys.exit(app.exec_())

mainform_impl.py:

Code: Alles auswählen

# -*- coding: utf-8 -*-

"""
Module implementing Mainform_Impl.
"""

from PyQt4.QtGui import QDialog
from PyQt4.QtCore import pyqtSignature

from Ui_test01 import Ui_Dialog

class Mainform_Impl(QDialog, Ui_Dialog):
    """
    Class documentation goes here.
    """
    def __init__(self, parent = None):
        """
        Constructor
        """
        QDialog.__init__(self, parent)
        self.setupUi(self)
        self.label.setText("HALLO WELT")           # <- DAS FÜHRT ZU KEINEM EFFEKT! WARUM BLOSS???
    
    @pyqtSignature("")
    def on_pushButton_clicked(self):
        """
        Slot documentation goes here.
        """
        # TODO: not implemented yet
        self.label.setText("HALLO")
        self.setWindowTitle("JAWOLL")     # <- UND DAS FÜHRT AUCH NICHT ZU EINER ÄNDERUNG DES TITELS... WIE ERREICHE ICH DAS???
        

Ui_test01.py:

Code: Alles auswählen

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file '/home/daniel/Develop/PyDevel/projects/PyQt4Test/test01.ui'
#
# Created: Sun Nov  4 18:21:05 2007
#      by: PyQt4 UI code generator 4.3.1
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

class Ui_Dialog(object):

    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(QtCore.QSize(QtCore.QRect(0,0,400,300).size()).expandedTo(Dialog.minimumSizeHint()))

        self.pushButton = QtGui.QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(200,250,76,28))
        self.pushButton.setObjectName("pushButton")

        self.label = QtGui.QLabel(Dialog)
        self.label.setGeometry(QtCore.QRect(40,30,271,61))
        self.label.setObjectName("label")

        self.retranslateUi(Dialog)
        QtCore.QObject.connect(self.pushButton,QtCore.SIGNAL("clicked()"),self.on_pushButton_clicked)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def on_pushButton_clicked(self):
        """
        Slot documentation goes here.
        """
        # TODO: not implemented yet
        raise "Not implemented yet"        

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("Dialog", "DO IT !", None, QtGui.QApplication.UnicodeUTF8))
        self.label.setText(QtGui.QApplication.translate("Dialog", "TextLabel", None, QtGui.QApplication.UnicodeUTF8))



if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    Dialog = QtGui.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())

Gruß
Daniel
Antworten