Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Space disappears after using Qstylesheet in QLabel
Qt 6.11 is out! See what's new in the release blog

Space disappears after using Qstylesheet in QLabel

Scheduled Pinned Locked Moved Solved Qt for Python
2 Posts 2 Posters 923 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.
  • feiyuhuahuoF Offline
    feiyuhuahuoF Offline
    feiyuhuahuo
    wrote on last edited by
    #1

    I want to let label_8 show different colors text. So I used stylesheet to do this. But I found that if stylesheet is used, the space in the string becomes useless.

            self.main_ui.label_8.setText(f'X: {x},   Y: {y} '
                                         f'<font color=red> R: {r}, </font>'
                                         f'<font color=green>      G: {g}, </font>'
                                         f'<font color=blue> B: {b} </font>')
    

    As the following picture shows, the text becomes compact.
    e258fe78-b734-4640-99e3-a8521f526be1-image.png
    Is there a way to adjust the space among different words and at the same time, keep only one QLabel being used.

    JonBJ 1 Reply Last reply
    0
    • feiyuhuahuoF feiyuhuahuo

      I want to let label_8 show different colors text. So I used stylesheet to do this. But I found that if stylesheet is used, the space in the string becomes useless.

              self.main_ui.label_8.setText(f'X: {x},   Y: {y} '
                                           f'<font color=red> R: {r}, </font>'
                                           f'<font color=green>      G: {g}, </font>'
                                           f'<font color=blue> B: {b} </font>')
      

      As the following picture shows, the text becomes compact.
      e258fe78-b734-4640-99e3-a8521f526be1-image.png
      Is there a way to adjust the space among different words and at the same time, keep only one QLabel being used.

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

      @feiyuhuahuo
      Since you have to use HTML text to put your colours in, you know that multiple spaces in HTML source only produce a single space in display output. I don't know what exactly QSS accepts, but try &nbsp; for an unbreakable space for each space desired, or a <pre> or maybe separate <span>s, or whatever works.

      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