QScrollView没有滚动条
我正在尝试制作一个带有大约 100 个不同标签和按钮的 QScrollView。 但是添加它们后,滚动条不会出现。
这是我编写的代码示例:
self.btn = {}
self.scroll = QScrollView(self)
self.scroll.setGeometry(QRect(0,0,300,300))
self.scroll.enableClipper(True)
vp = self.scroll.viewport()
for i in range(0,100):
self.btn[i] = QPushButton(vp)
for i in range(0,100):
self.scroll.addChild(self.btn[i],1,50*i)
self.scroll.setVScrollBarMode(QScrollView.AlwaysOn) 使滚动条出现但不起作用。
这些按钮已添加到 QScrollView 但我无法向下滚动以查看全部按钮 我做错了什么?我用的是qt3。
I'm trying to make a QScrollView with around 100 different labels and buttons.
But after I add them, the scrollbars do not appear.
here is an example of the code I wrote:
self.btn = {}
self.scroll = QScrollView(self)
self.scroll.setGeometry(QRect(0,0,300,300))
self.scroll.enableClipper(True)
vp = self.scroll.viewport()
for i in range(0,100):
self.btn[i] = QPushButton(vp)
for i in range(0,100):
self.scroll.addChild(self.btn[i],1,50*i)
self.scroll.setVScrollBarMode(QScrollView.AlwaysOn)
make the scrollbar appear but not to work.
The buttons get added to the QScrollView but I can't scroll down to see them all
what am I doing wrong? I'm using qt3.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不会将所有小项目添加到滚动视图中。您必须将一个大型容器(例如 QFrame 派生类)插入到包含所有较小部件的滚动视图中。
You don't add all your little items to the scrollview. You have to insert a single, large container (a QFrame derived class, for example) into the scrollview that contains all your smaller widgets.
实际上你只需要给滚动视图一个布局并将你的小部件添加到其中。将它们添加为滚动视图中一个大小部件的子小部件将为您做到这一点,但它更混乱。
Actually you just need to give the scroll-view a layout and add your widgets to this. Adding them as sub-widgets of one big widget within the scrollview will do this for you, but it's messier.