1

我在使用 PySide 设计窗口时遇到问题。

class MainForm(QWidget):
    def __init__(self, parent=None):
        super(MainForm, self).__init__()
        # init window

        self.hbox = QHBoxLayout(self)

        self.scroll = QScrollArea(self)

        self.table = QTableWidget(self)

        self.leftspltr = QSplitter(QtCore.Qt.Vertical)
        self.rightspltr = QSplitter(QtCore.Qt.Vertical)

        self.scroll.setWidget(self.leftspltr)
        self.rightspltr.addWidget(self.table)         

        self.hbox.addWidget(self.leftspltr)
        self.hbox.addWidget(self.rightspltr)


        self.setWindowTitle("...")

        self.table.setColumnCount(3)
        self.table.move(11,220)
        self.table.verticalHeader().hide()
        self.table.setHorizontalHeaderLabels(["Key","Full","HR"])

        dic = dumpered_hash.dict_naming_values
        os.popen("rm dumpered_hash dumpered_hash.py dumpered_hash.pyc")

        xpos = 0
        ypos = 0
        for key, val1 in sorted(dic.iteritems()):
            btn = QPushButton(key, self)
            btn.clicked.connect(partial(self.fillTbl, val1, len(val1) + 1))
            btn.setFixedSize(84,20)
            self.leftspltr.addWidget(btn)

滚动m trying to design a window that has some button (more than 30) placed virtically, so I want to have them in scroll bar that fits the window size, and a table at the right side that doesn时它不会移动。上面的代码给了我一个移动按钮的小滚动条,但它们超出了窗口大小。

有什么问题?

4

1 回答 1

0

我想我明白你在这里想要做什么。但是,您将按钮放置在垂直拆分器中,然后固定它们的大小。相反,将按钮放置在垂直布局中,然后将其和表格小部件放置到水平拆分器中。

class MainForm(QtGui.QWidget):
    def __init__(self, parent=None):
        super(MainForm, self).__init__()
        # init window

        self.hbox = QtGui.QHBoxLayout(self)

        self.btnbox = QtGui.QVBoxLayout()

        self.scroll = QtGui.QScrollArea(self)

        self.table = QtGui.QTableWidget(self)

        self.spltr = QtGui.QSplitter(QtCore.Qt.Horizontal)

        self.setWindowTitle("...")

        self.table.setColumnCount(3)
        self.table.move(11,220)
        self.table.verticalHeader().hide()
        self.table.setHorizontalHeaderLabels(["Key","Full","HR"])

        dic = {}
        for i in range(30):
            dic['foo '+str(i)] = [i]

        for key, val1 in sorted(dic.iteritems()):
            btn = QtGui.QPushButton(key, self)
            self.btnbox.addWidget(btn)

        # must place layout into a widget before adding to QScrollArea
        holder = QtGui.QWidget()
        holder.setLayout(self.btnbox)
        self.scroll.setWidget(holder)  
        self.spltr.addWidget(self.scroll)
        self.spltr.addWidget(self.table)         

        self.hbox.addWidget(self.spltr)

我还想指出,最好包含重现问题所需的最简单的代码。我不知道你想用包含的行来实现什么dumpered_hash,但这似乎是无关紧要的,以及对不推荐使用的函数的可疑使用,并且在不修改的情况下无法运行你的代码。让人们更容易帮助你!

于 2013-09-10T16:52:34.873 回答