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. <br> formatting problem in QLabel

<br> formatting problem in QLabel

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 815 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.
  • T Offline
    T Offline
    torea
    wrote on last edited by
    #1

    Hello,

    I have a problem with some text I want to display inside cells of a QTableWidget.
    Some of the cells are initialized with

    setCellWidget( row, col, cellLabel );
    

    cellLabel is basically a QLabel which contents is set with something like

    setText( "<center>1 (2) </center><font color=#000000>09:12 : <b>titre Normal</b></font><br/><font color=#FF1144>12:10 : <b>titre Rouge</b></font><br/>" );
    

    this gives the following result, where "09:12 : " and "titre Normal" end up on different lines.
    problemFormatQLabel.png

    If I add a <br/> after the </center>, the hours and title are on the same line but I get an extra blank line between the "1 (2)" and the following lines.

    In my example, I would like to have only 3 lines:
    1 (2)
    09:12 : titre Normal
    12:10 : titre Rouge

    How could I achieve this?

    JonBJ 1 Reply Last reply
    0
    • T torea

      Hello,

      I have a problem with some text I want to display inside cells of a QTableWidget.
      Some of the cells are initialized with

      setCellWidget( row, col, cellLabel );
      

      cellLabel is basically a QLabel which contents is set with something like

      setText( "<center>1 (2) </center><font color=#000000>09:12 : <b>titre Normal</b></font><br/><font color=#FF1144>12:10 : <b>titre Rouge</b></font><br/>" );
      

      this gives the following result, where "09:12 : " and "titre Normal" end up on different lines.
      problemFormatQLabel.png

      If I add a <br/> after the </center>, the hours and title are on the same line but I get an extra blank line between the "1 (2)" and the following lines.

      In my example, I would like to have only 3 lines:
      1 (2)
      09:12 : titre Normal
      12:10 : titre Rouge

      How could I achieve this?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @torea
      For unknown reason, you are showing that

      <font color=#000000>09:12 : <b>titre Normal</b></font><br/>
      

      splits the line, while seemingly-identical

      <font color=#FF1144>12:10 : <b>titre Rouge</b></font><br/>
      

      appears not to.

      I don't know the answer, other than playing around, but you seem to know your HTML so I would try using <span> and/or <div> elements. Or, maybe play with &nbsp; if you absolutely have to. Etc.

      P.S.
      If @VRonin sees you using setCellWidget() at all you will be in trouble! Since he will advise using a QStyledItemDelegate here instead, you might want to change your code over to that, and then deal with any problems. Though I don't know whether text there is allowed to be HTML/rich-text or just plain text.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        torea
        wrote on last edited by
        #3

        Thanks for the hints.
        Some other parts of the software use the HTML formatting so I'm supposed to keep the HTML.
        I'll try to play with the elements you mentioned and will check if the QStyledItemDelegate can accept HTML.

        If nothing works, we'll probably stick to the "blank line" solution

        1 Reply Last reply
        0
        • T Offline
          T Offline
          torea
          wrote on last edited by
          #4

          Using <div> elements to separate the lines instead of <br> solved the problem.

          setText( "<div><center>1 (2) </center></div><div><font color=#000000>09:12 : <b>titre Normal</b></font></div><div><font color=#FF1144>12:10 : <b>titre Rouge</b></font></div>" );
          
          1 Reply Last reply
          1

          • Login

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