Show a QStringList in QLabel
-
@sterbilly
Yes, that is what your code does, overwrites the text on each iteration. How do you want it to be displayed?ui->label_out->setText(ex.join(' ')); ui->label_out->setText(ex.join(',')); ui->label_out->setText(ex.join(', ')); ui->label_out->setText(ex.join('\n'));
One of those? No loop if you use
join()
. Otherwise loop:ui->label_out->setText(ui->label_out->text() + ex[i])
Or,
QLabel
is not the best widget choice, maybe you want aQListWidget
? -
Ok, thank you, with the loop it displayed more string, but how I can go to the end of the line after every artist string in QLabel? And if I want to do it in a QTextBrowser?
At the end, in a QLabel or in a QTextBrowser I need to have a list of artist with hyperlink.row_uni read every single line of txt file and extract link and name of an artist.
Var artist is a QString with link to the wikipedia page. It change for every line I read in a file.
window_uni is a QTextBrowser.for (int i=0; i<100; i++) { row_uni = in.readLine(); url=row_uni.section('"', 1, 1); link = "https://it.wikipedia.org"+url; artist = row_uni.section(' ', 1, 1); ui->label_out->setText(ui->label_out->text() + "<a href=\""+link+"\">"+artist+"</a>"); //ui->window_uni-> ??? }
-
@sterbilly said in Show a QStringList in QLabel:
but how I can go to the end of the line after every artist string in QLabel?
I don't understand what that means. If I have to guess, if you mean put in a line break to move down to the next line, that would be
<br />
in HTML5.You cannot put a
QLabel
onto aQTextBrowser
. You can put HTML into it.