Solved How to add new line in Qlabel
-
Hi,
i have a list. It has two indexes. I have been trying to display these 2 index on Qlabel. I used\n
and i setsetWordWrap
propertyTrue
. But both didn't work. I see always just second element.for x in the_list: self.label_3.setText(" %d \n"%x) self.label.setWordWrap=True print("\n") print(x)
here is the result
-
@hernancrespo89
You can't callsetText()
twice in the way you show, if that's what you mean. You have to build the two line string andline = "line 1" line += "\n line 2" self.label.setText(line)
or
self.label.setText("line 1") self.label.setText(self.label.text() + "\n line 2")
-
So where do you actually set the second value? I only see setText() with one argument passed to your string.
-
But setText() need one argument. I'm trying set first and second value in for loop
-
@hernancrespo89
You can't callsetText()
twice in the way you show, if that's what you mean. You have to build the two line string andline = "line 1" line += "\n line 2" self.label.setText(line)
or
self.label.setText("line 1") self.label.setText(self.label.text() + "\n line 2")