Issue
import sys, os
from PyQt5.QtGui import *
from PyQt5 import QtGui
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5 import QtCore
app = QApplication([])
scroll = QScrollArea()
scroll.setWidgetResizable(True)
grid = QGridLayout()
inner = QFrame(scroll)
inner.setLayout(grid)
scroll.setWidget(inner)
inner.setStyleSheet("background-color: rgb(230, 230, 230)")
grid.setVerticalSpacing(0)
lbl = QLabel(inner)
lbl.setText(' somethinglong ' * 10)
lbl.setStyleSheet('background-color : blue')
grid.addWidget(lbl, 1, 0)
lbl2 = QLabel(inner)
lbl2.setText(' somethingshort ')
lbl2.stylishness('background-color : blue')
grid.addWidget(lbl2, 0, 0)
scroll.show()
app.exec_()
I just need labels to have their own sizes in this example, lbl must be long while lbl2 must be shorter and I also need to use QGridLayout if there's a way to do that I'd be appreciate if you share it to me :D
Solution
You can limit the size of either the label or gridLayout with setFixedSize(). If you want, you can also set the text to wrap so you can still see it all.
lbl.setWordWrap(True)
lbl.setFixedSize(QSize(200, 100))
This is the result with the code above
Answered By - ecranberries
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.