0

In my application there is QTextBrowser widget and the data will be appended to it for every 1 second. I know that when data hits the bottom of the widget, a vertical scroll bar will be created. But, Is it possible to expand the size of QTextBrowser widget (not using QLayout) by the user via mouse drag whenever it is required ?

If yes, please help me out.

Here's my piece of code.

#!/usr/bin/python
from PyQt4 import QtGui
from PyQt4 import QtCore
from PyQt4.QtGui import QSplitter
from PyQt4.QtGui import QTextEdit

import sys

class Commit(QtGui.QMainWindow):
    def __init__(self):
        super(Commit, self).__init__()
        self.initUI()

    def initUI(self):
        self.qle = QtGui.QLineEdit(self)
        self.qle.setFixedWidth(450) # tab width
        self.qle.move(20, 35) # tab position

        self.browser = QtGui.QTextBrowser(self)
        self.browser.resize(420, 100)
        self.browser.move(34, 100)

        self.lbl = QtGui.QLabel(self)
        self.lbl.setGeometry(10, 55,200,20)
        self.lbl.setText("Enter input here")
        self.lbl.move(200,10) # label position

        self.setGeometry(300, 300, 500, 250)
        self.show()

def main():
    app = QtGui.QApplication(sys.argv)
    commit = Commit()
    commit.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()
mg1
  • 101
  • 1
  • 6

1 Answers1

0

You can use QSizeGrip:

from PyQt4 import QtCore, QtGui

class Commit(QtGui.QMainWindow):
    def __init__(self):
        super(Commit, self).__init__()
        self.initUI()

    def initUI(self):
        self.qle = QtGui.QLineEdit(self)
        self.qle.setFixedWidth(450) # tab width
        self.qle.move(20, 35) # tab position

        self.browser = QtGui.QTextBrowser(self)
        self.browser.setGeometry(34, 100, 420, 100)

        self.browser.setWindowFlags(QtCore.Qt.SubWindow)
        size_grip = QtGui.QSizeGrip(self.browser)
        lay = QtGui.QVBoxLayout(self.browser)
        lay.addWidget(size_grip, alignment= QtCore.Qt.AlignBottom | QtCore.Qt.AlignRight)

        self.lbl = QtGui.QLabel(self)
        self.lbl.setGeometry(200,10, 200,20)
        self.lbl.setText("Enter input here")

        self.setGeometry(300, 300, 500, 250)
        self.show()

def main():
    import sys
    app = QtGui.QApplication(sys.argv)
    commit = Commit()
    commit.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()

Now if you move the mouse on the bottom-right side you will see that the cursor changes icon, in that moment you can change the size by dragging the mouse.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • @mg1 If my answer helps you, do not forget to mark it as correct if you do not know how to do it, review the [tour], that is the best way to thank. :-) – eyllanesc Oct 30 '18 at 15:16