Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Show a QStringList in QLabel
Forum Updated to NodeBB v4.3 + New Features

Show a QStringList in QLabel

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 793 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sterbilly
    wrote on last edited by
    #1

    How can I show in my QLabel my list? Now I see only "test3".

    
    QStringList ex = {"test1", "test2", "test3"};
    for (int i = 0; i<3; i++) {
            ui->label_out->setText(ex[i]); //is a QLabel
    }
      
    
    JonBJ 1 Reply Last reply
    0
    • S sterbilly

      How can I show in my QLabel my list? Now I see only "test3".

      
      QStringList ex = {"test1", "test2", "test3"};
      for (int i = 0; i<3; i++) {
              ui->label_out->setText(ex[i]); //is a QLabel
      }
        
      
      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @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 a QListWidget?

      1 Reply Last reply
      3
      • S Offline
        S Offline
        sterbilly
        wrote on last edited by
        #3

        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-> ???
         }
        
        JonBJ 1 Reply Last reply
        0
        • S sterbilly

          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-> ???
           }
          
          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @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 a QTextBrowser. You can put HTML into it.

          1 Reply Last reply
          1
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            QTextBrowser has a append method.

            However you might as well build your QString content and then set the final html on the QTextBrower.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved