繁体   English   中英

如何使用 python 在 pyqt5 中自动启用水平和垂直滚动条

[英]How to auto enable the Horizontal and Vertical scroll-bar in pyqt5 using python

我是 PyQt5 和 Python 的新手,我的问题是如果用户在输入框的单行中输入更多数据,如何启用水平滚动条?

目前,如果您输入更多数据,它的输入框会启用垂直滚动条。

如果用户输入更多数据,谁能帮我解决如何同时启用水平和垂直滚动条?

当前 Python 代码:

import sys

from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtCore import QSize
from PyQt5.QtWidgets import *
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog
from PyQt5.QtWidgets import QMainWindow, QApplication, QLabel

class MainWindow(QMainWindow, QWidget):
    def __init__(self):
        QMainWindow.__init__(self)
        self.height = 480
        self.width = 640
        self.top = 10
        self.left = 10
        self.setWindowFlags(QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.WindowMinimizeButtonHint)
        self.setMinimumSize(QSize(800, 600))
        self.setWindowTitle("My Windows")

        # .... other Code here

        # Edit Box
        input_et_box = QFrame(self)
        input_et_box.resize(300, 450)
        input_et_box.move(50, 80)
        layout = QHBoxLayout(input_et_box)
        self.textEdit = QTextEdit(self)
        layout.addWidget(self.textEdit)

        # If we enter more data in Edit Box it will automatically enabled Vertical Scroll bar but Horizontal Scroll bar is not enabling automatically
        # bar is not enabling

    def printHello(self):
        print("Hello")


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    layout = QGridLayout()
    mainWin = MainWindow()
    mainWin.show()
    sys.exit(app.exec_())

快照:

在此处输入图像描述

在此处输入图像描述

使用self.textEdit.setLineWrapMode(QTextEdit.FixedPixelWidth)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM