我在使用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
移动。
上面的代码给了我一个小小的滚动条移动按钮,它们超出窗口大小。
那边有什么不对?
答案 0 :(得分: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
的行来实现什么,但它似乎是无关紧要的,以及对不推荐使用的函数的可疑使用,并且无法在不进行修改的情况下运行代码。让人们更容易帮助您!