Reputation: 1407
I have a QWidget
called side
and QTextEdit
inside it's sideLayout
layout.
chatView = QTextEdit()
chatView.setHtml('<p style="margin: 0px; line-height: 28px;">')
sideLayout.addWidget(tab.chatView, 0, 0, 1, 1)
Below the QTextEdit
there's a QLineEdit
called inputLine
, where I write text and send it to QTextEdit
via .append(inputLine.text())
on Return
.
I want each new line (the <p>
element) to appear on the bottom, and each new line being appended below first one.
This is how it looks now:
I tried setStylesheet()
with p { vertical-align: bottom; }
.
I tried p { position: absolute; bottom: 0px; }
I tried setAlignment()
with Qt.AlignBottom
.
How can I make lines align to the bottom like this?
Upvotes: 2
Views: 3926
Reputation: 120778
If the chat-view is going to be read-only, you don't really need a text-edit. Just use a QLabel
, and then setAligment
will work as expected:
self.chatView = QtGui.QLabel(self)
self.chatView..setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom)
To append text, you can do something like:
self.chatView.setText(
'%s<p>%s</p>'
% (self.chatView.text(), self.inputLine.text()))
(PS: you may also need to put the label in a QScrollArea
).
Upvotes: 5