python – PyQt:把滚动条放在这里
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python – PyQt:把滚动条放在这里,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3131字,纯文字阅读大概需要5分钟。
内容图文
这是我的班级:
class ChildFoundDlg(QDialog):
#__init__ function:
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.resize(500, 270)
self.setMaximumSize(500, 540)
self.GridLayout = QtGui.QGridLayout(self)
def buttons(self, a, b, c): #a = 0, b = 5 c = 7
self.font = QtGui.QFont("Sans Serif", 10, QFont.Normal)
self.label = QtGui.QLabel(self)
self.label.setText(QtGui.QApplication.translate("Form", "Μ?πω? εννοε?τε την/τον:", None, QtGui.QApplication.UnicodeUTF8))
self.label.setFont(self.font)
self.GridLayout.addWidget(self.label, a, 0, 1, 1)
self.label2 = QtGui.QLabel(self)
self.GridLayout.addWidget(self.label2, a, 1, 1, 1)
self.label2.setFont(self.font)
self.pushButton = QtGui.QPushButton(self)
self.GridLayout.addWidget(self.pushButton, b, 0, 2, 1)
self.pushButton.setText(QtGui.QApplication.translate("Form", "Υπ?τροπο?", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding)
self.pushButton2 = QtGui.QPushButton(self)
self.GridLayout.addWidget(self.pushButton2, b, 1, 2, 1)
self.pushButton2.setText(QtGui.QApplication.translate("Form", "Αναβολ?", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton2.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding)
self.pushButton3 = QtGui.QPushButton(self)
self.GridLayout.addWidget(self.pushButton3, c, 1, 2, 1)
self.pushButton3.setText(QtGui.QApplication.translate("Form", "Ακ?ρωση", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton3.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding)
self.pushButton3.clicked.connect(self.reject)
我想要实现的是,当我用不同的值调用self.buttons很多次时,
当达到对话框的最大大小时,停止放大但改为放滚动条,如果你明白我在说什么……我怎么能这样做?
解决方法:
以下是使用QScrollArea的示例:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from PyQt4 import QtCore, QtGui
class myDialog(QtGui.QDialog):
_buttons = 0
def __init__(self, parent=None):
super(myDialog, self).__init__(parent)
self.pushButton = QtGui.QPushButton(self)
self.pushButton.setText(QtGui.QApplication.translate("self", "Add Button!", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.clicked.connect(self.on_pushButton_clicked)
self.scrollArea = QtGui.QScrollArea(self)
self.scrollArea.setWidgetResizable(True)
self.scrollAreaWidgetContents = QtGui.QWidget(self.scrollArea)
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 380, 247))
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.verticalLayout = QtGui.QVBoxLayout(self)
self.verticalLayout.addWidget(self.pushButton)
self.verticalLayout.addWidget(self.scrollArea)
self.verticalLayoutScroll = QtGui.QVBoxLayout(self.scrollAreaWidgetContents)
@QtCore.pyqtSlot()
def on_pushButton_clicked(self):
self._buttons += 1
pustButtonName = u"Button {0}".format(self._buttons)
pushButton = QtGui.QPushButton(self.scrollAreaWidgetContents)
pushButton.setText(pustButtonName)
self.verticalLayoutScroll.addWidget(pushButton)
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
app.setApplicationName('myDialog')
main = myDialog()
main.show()
sys.exit(app.exec_())
内容总结
以上是互联网集市为您收集整理的python – PyQt:把滚动条放在这里全部内容,希望文章能够帮你解决python – PyQt:把滚动条放在这里所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。