PySide6 QWidget更改窗口标题


PySide6.QtWidgets.QWidget类的成员函数setWindowTitle()用于为窗口更改标题;

示例代码

import sys
from PySide6 import QtCore, QtWidgets, QtGui

class MyWidget(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()

        self.button = QtWidgets.QPushButton("修改标题")

        self.layout = QtWidgets.QVBoxLayout(self)
        self.layout.addWidget(self.button)

        self.button.clicked.connect(self.setTitle)

    @QtCore.Slot()
    def setTitle(self):
        self.setWindowTitle("perfcode.com")#修改标题

if __name__ == "__main__":
    app = QtWidgets.QApplication([])
    widget = MyWidget()
    widget.resize(300, 200)

    widget.setWindowTitle("hello world")#修改标题

    widget.show()
    sys.exit(app.exec())

如需转载,请注明出处;本文地址:https://www.perfcode.com/p/pyside6-qtwidgets-qwidget-setwindowtitle.html