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. How to add new line in Qlabel
Forum Updated to NodeBB v4.3 + New Features

How to add new line in Qlabel

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 4.7k Views
  • 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.
  • H Offline
    H Offline
    hernancrespo89
    wrote on last edited by
    #1

    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 set setWordWrap property True. 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 Untitled.png

    1 Reply Last reply
    0
    • H hernancrespo89

      @Christian-Ehrlicher

      But setText() need one argument. I'm trying set first and second value in for loop

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #4

      @hernancrespo89
      You can't call setText() twice in the way you show, if that's what you mean. You have to build the two line string and

      line = "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")
      
      1 Reply Last reply
      3
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        So where do you actually set the second value? I only see setText() with one argument passed to your string.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        H 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          So where do you actually set the second value? I only see setText() with one argument passed to your string.

          H Offline
          H Offline
          hernancrespo89
          wrote on last edited by
          #3

          @Christian-Ehrlicher

          But setText() need one argument. I'm trying set first and second value in for loop

          JonBJ 1 Reply Last reply
          0
          • H hernancrespo89

            @Christian-Ehrlicher

            But setText() need one argument. I'm trying set first and second value in for loop

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #4

            @hernancrespo89
            You can't call setText() twice in the way you show, if that's what you mean. You have to build the two line string and

            line = "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")
            
            1 Reply Last reply
            3

            • Login

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