我正在尝试使用 pyqt5 创建一个具有垂直布局的滚动区域,并且我放入了一些标签。我知道即使它是垂直布局,如果文本不适合,它也应该水平滚动。但无论我尝试什么,它都不让我滚动。
这是我正在使用的代码:
class window(QMainWindow):
def __init__(self):
super(window, self).__init__()
self.setGeometry(300, 300, 803, 520)
self.init_ui()
def init_ui(self):
self.teacher_box = QScrollArea(self)
self.teacher_box.setGeometry(360, 10, 420, 181)
self.teacher_box.setWidgetResizable(True)
self.teacher_box.setObjectName("teacher_box")
self.teacher_box_widget = QWidget()
self.teacher_box_widget.setGeometry(QtCore.QRect(0, 0, 420, 181))
self.teacher_box_widget.setObjectName("teacher_box_widget")
self.verticalLayout = QVBoxLayout(self.teacher_box_widget)
self.verticalLayout.setObjectName("verticalLayout")
self.teacher_box.setWidget(self.teacher_box_widget)
self.teacher_label = QtWidgets.QLabel(self.teacher_box_widget)
self.teacher_label.setText("This is a new text label that i created using pyqt5's qscrollarea and now the label is going to get outside the boundaries")
self.teacher_label.adjustSize()
self.teacher_label.move(10, 10)
if __name__ == "__main__":
app = QApplication(sys.argv)
win = window()
win.show()
sys.exit(app.exec_())
它应该是这样的:
它看起来是这样的:
汪汪一只猫
相关分类