将内容添加到 pyqt4 滚动区域 [英] Adding Content to pyqt4 scroll area

查看:54
本文介绍了将内容添加到 pyqt4 滚动区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将内容添加到 pyqt4 中的滚动区域?我自定义定义一个小部件吗?例如,如果我有一个数组或一个列表a =[10,2,2,2,22,3,3,3].我应该如何在滚动条区域显示变量?

How can I add content to a scroll area in pyqt4? DO i custom define a widget? For example, if i had a array or a lista =[10,2,2,2,22,3,3,3]. How should I display teh variable in the scrollbar area?

推荐答案

如果您想向滚动区域添加内容,您需要定义一个新的小部件并将其添加到滚动区域 - 就像您将一个小部件添加到一个框架.例如:

If you want to add content to a scroll area, you need to define a new widget and add that to the scroll area - like you would add a widget to a frame. For example:

textEdit = QtGui.QTextEdit()
scrollArea = QtGui.QScrollArea(MainWindow)
scrollArea.setWidget(textEdit)

然后,您可以使用 textEdit.append() 或 textEdit.setText() 将数组中的数据添加到滚动区域的文本框中.文档说明了一切,真的,虽然是用 C 而不是 python,但很明显你需要做什么:

Then, you can use textEdit.append() or textEdit.setText() to add the data in the array to the text box in the scroll area. The documentation says it all, really, albeit in C rather than python, but its obvious what you need to do:

QLabel *imageLabel = new QLabel;
QImage image("happyguy.png");
imageLabel->setPixmap(QPixmap.fromImage(image));

scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette.Dark);
scrollArea->setWidget(imageLabel);

这篇关于将内容添加到 pyqt4 滚动区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆