Answer the question
In order to leave comments, you need to log in
QLabel text out of bounds?
I've been struggling with this problem all day. I created a ScrollArea, the user enters text and it has to fit on the ScrollArea, which it does poorly. The error is that the text goes beyond the boundaries of the application. The setWordWrap() and WordWrap() method has already been used, it didn't work.
#Тут создаю scrollarea и label в котором написано "Напишите любое сообщение" (с надписью все норм, так что не #обращаем особо внимания)
self.scrollArea_2 = QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea_2.setGeometry(QtCore.QRect(200, 60, 601, 461))
font = QtGui.QFont()
font.setFamily("Comic Sans MS")
font.setPointSize(15)
self.scrollArea_2.setFont(font)
self.scrollArea_2.setWidgetResizable(False)
self.scrollArea_2.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
self.scrollArea_2.setObjectName("scrollArea_2")
self.scrollAreaWidgetContents_2 = QtWidgets.QWidget()
self.scrollAreaWidgetContents_2.setGeometry(QtCore.QRect(0, 0, 599, 459))
self.scrollAreaWidgetContents_2.setObjectName("scrollAreaWidgetContents_2")
self.lbl = QtWidgets.QLabel(self.scrollAreaWidgetContents_2)
self.lbl.setGeometry(QtCore.QRect(350, 420, 240, 25))
self.lbl.setObjectName("lbl")
#Дальше в функции конектимся к смене текста (PushButton все норм, вопросов нет)
def add_func(self):
self.pushButton_4.clicked.connect(lambda: self.send_message())
#И дальше начинается... Сама функция измены текста
def send_message(self):
_translate = QtCore.QCoreApplication.translate
if self.plainTextEdit.toPlainText() != '':
self.lbl.setText(_translate("MainWindow", self.plainTextEdit.toPlainText()))
self.lbl.adjustSize()
Answer the question
In order to leave comments, you need to log in
Where is the setWidget call?
import sys
from PySide2.QtWidgets import QApplication, QScrollArea, QLabel
class Main(QScrollArea):
def __init__(self):
super(Main, self).__init__()
self.resize(300, 300)
# вариант 1, не работает
# self.label = QLabel('some text', self)
# вариант 2, работает
self.label = QLabel("some text")
self.setWidget(self.label)
self.label.setStyleSheet("background-color: rgba(255,0,255)")
self.label.resize(500, 100)
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = Main()
ex.show()
sys.exit(app.exec_())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question