0

I'm new to PyQt5 and Python, My question is how to enable the Horizontal scroll-bar if user enter more data in single line of the input box?

Currently it Input box enabling vertical scroll-bar if you enter more data.

can any one help me out how to enable both horizontal and Vertical scroll-bar if user enter more data?

Current Python Code:

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_())

Snapshot:

enter image description here

enter image description here

1
  • Please any one have a look on this , Thanks in advance May 23, 2020 at 17:00

1 Answer 1

0

Use self.textEdit.setLineWrapMode(QTextEdit.FixedPixelWidth)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.