Issue
I have a QLabel
inside a QFrame
.
Sometimes I have too much text in the QLabel
and it resizes the QFrame
where it is in.
Now, I want to prevent the QLabel
from resizing the QFrame
where it resides in.
I don't want to limit the amount of lines or setting the maximum size of the QLabel
because if the window size of the app increases, I do want to allow the QLabel
to increase in size.
Just want to prevent the QLabel
from expanding it's parent.
Any clean way to do it?
Solution
Use a QScrollArea
(which inherits QFrame
), and hide its scrollbars:
label = QtGui.QLabel(text)
frame = QtGui.QScrollArea()
frame.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
frame.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
frame.setWidgetResizable(True)
frame.setWidget(label)
This has the side-benefit that the user will still be able to view any hidden text by scrolling with the mouse-wheel.
Answered By - ekhumoro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.