pyside ui 中的拆分器现在可见

splitter in pyside ui now visible

为什么选项卡中没有显示拆分器?

我不完全确定哪里出了问题。我猜测布局框未调整大小以匹配选项卡的大小,在 return 中在选项卡中生成如此小的 window,不足以显示其内容。欢迎任何代码建议。

import sys
from PySide import QtGui, QtCore

class Example(QtGui.QWidget):

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

        self.initUI()

    def initUI(self):      

        # controls - main
        # ----------------------------------------------------------------------
        main_tabWidget = QtGui.QTabWidget()

        # controls - factions tab
        # ----------------------------------------------------------------------
        factions_tab = QtGui.QWidget()
        factions_tab_layout = QtGui.QHBoxLayout()

        topleft = QtGui.QFrame(factions_tab)
        topleft.setFrameShape(QtGui.QFrame.StyledPanel)

        topright = QtGui.QFrame(factions_tab)
        topright.setFrameShape(QtGui.QFrame.StyledPanel)

        splitter1 = QtGui.QSplitter(QtCore.Qt.Horizontal)
        splitter1.addWidget(topleft)
        splitter1.addWidget(topright)

        factions_tab_layout.addWidget(splitter1)
        QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks'))

        main_tabWidget.addTab(factions_tab, "Factions")

        # main layout
        # ----------------------------------------------------------------------
        main_layout = QtGui.QVBoxLayout()
        main_layout.addWidget(main_tabWidget)

        self.setLayout(main_layout)
        self.setGeometry(300, 300, 400, 300)
        self.setWindowTitle('Example')
        self.center()
        self.show()

    def center(self):
        qr = self.frameGeometry()
        cp = QtGui.QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())

    def onChanged(self, text): 
        self.lbl.setText(text)
        self.lbl.adjustSize()        


def main():

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


if __name__ == '__main__':
    main()

factions_tab_layout 从未被赋予父级,也未在任何小部件上设置为布局。这意味着它的子部件将在 initUI returns 时被垃圾回收,因为你也没有给它们任何父部件。

最小修复:

    factions_tab_layout = QtGui.QHBoxLayout(factions_tab)