4
I’m making a small application in Pyqt4 to understand how it works.
In a certain part, I’m using a callback function to display in a QLabel
the text that is typed in QtextEdit
.
This text should be trimmed (remove spaces before and after the string).
When I tried to use the function strip
present in str
Python the following error occurred:
Attributeerror: 'Qstring' Object has no attribute 'strip'
From what I understand, in Pyqt, the string is not an object str
and yes QString
and QString
does not have the method strip
.
In that case, what can I do to get my string handled?
Code:
def onButtonOkClicked(self):
def setText():
text = self.line.toPlainText().strip();
self.label.setText(text)
QtCore.QObject.connect(self.buttonOk, QtCore.SIGNAL("clicked()"), setText)
Where is being used the
strip()
?– Maniero
I don’t use much Qt in python (only in C++ anyway), but the
QString
has the functiontrimmed
, removing whitespace at the beginning and end. It would be equivalent tostrip
? http://doc.qt.io/qt-4.8/qstring.html#trimmed– C. E. Gesser
@C.E.Gesser puts, it worked. I thought it would be solved in another way :p
– Wallace Maxters
@bigown found the right code (the wrong code that generated the question). The idea of the question came up at the same time that I was editing here, kkkk
– Wallace Maxters
Qstring is different from python string, I think this is the reason for the problem, however I still do not understand the goal, I will try to run pyqt here to test.
– Guilherme Nascimento
@Guilhermenascimento as said in the question, the goal is to pass the text of Qtextedit to Qlabel. But I want Qlabel to be like the text "clean"
– Wallace Maxters