1つのQScrollAreaに1つまたは複数のQGroupBoxを挿入しようとしています。Python + PyQt5:1つまたは複数のQGroupBoxにQScrollAreaを使用するにはどうすればいいですか?
問題は次のとおりです。スクロールバーが表示されない。私はこの効果を実現したい
# -*- coding: utf-8 -*-
from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QCheckBox
from PyQt5.QtWidgets import QGroupBox
from PyQt5.QtWidgets import QScrollArea
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, QGridLayout
import sys
lst = [u"D", u"E", u"EF", u"F", u"FG", u"G", u"H", u"JS", u"J", u"K", u"M", u"P", u"R", u"S", u"T", u"U", u"V", u"X", u"Y", u"Z"]
class MyApp(QWidget):
def __init__(self):
super(MyApp, self).__init__()
window_width = 1200
window_height = 600
self.setFixedSize(window_width, window_height)
self.initUI()
def createLayout_group(self):
self.groupbox = QGroupBox(u"Group1:")
self.layout_groupbox = QVBoxLayout()
for i in range(len(lst)):
self.item = QCheckBox(lst[i], self.groupbox)
self.layout_groupbox.addWidget(self.item)
self.layout_groupbox.addStretch(1)
self.groupbox.setLayout(self.layout_groupbox)
def createLayout_Container(self):
self.scrollarea = QScrollArea(self)
self.scrollarea.setFixedSize(250, 6000)
self.scrollarea.setWidgetResizable(False)
self.layout_SArea = QVBoxLayout()
self.layout_SArea.addWidget(self.groupbox)
self.layout_SArea.addWidget(self.groupbox) # add groupbox one more to test
self.layout_SArea.addWidget(self.groupbox) # add groupbox one more to test
self.layout_SArea.addStretch(1)
self.scrollarea.setLayout(self.layout_SArea)
def initUI(self):
self.createLayout_group() # load one groupbox
self.createLayout_Container() # load groupbox container
self.layout_All = QVBoxLayout()
self.layout_All.addWidget(self.scrollarea)
self.setLayout(self.layout_All)
self.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MyApp()
sys.exit(app.exec_())
:
は、ここに私のコードです。 (ちょうど表現のため)しかし、上のコードは、スクロールを示していません。
ありがとうございました!あなたの素敵な説明とコードのためにあなたはとても親切です!私は本当にPyQtの初心者です。私は本当に学ぶべきことがたくさんあるようです。 –
Qscroll Area.Actuallyで私はレイアウトを理解していないので、今すぐPyQtをやっています。 –
QScrollAreaには既にviewport()が設定されているデフォルトレイアウトがありますスクロールのプロパティを削除します。 – eyllanesc