Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Function to set Text as superscript or subscript or change the text color of particular alphabet

Function to set Text as superscript or subscript or change the text color of particular alphabet

Scheduled Pinned Locked Moved Solved Mobile and Embedded
8 Posts 2 Posters 2.5k 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.
  • PopQtP Offline
    PopQtP Offline
    PopQt
    wrote on last edited by
    #1

    I would like to set my Text as superscript or subscript or change the text color of particular alphabet. Is there any in-built function in QT. I found examples to change the background color of particular alphabet, But it didn't help me
    Note: I am not using any form or qml for design.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi!

      I am not using any form or qml for design

      So, how do you render your text?

      PopQtP 1 Reply Last reply
      0
      • ? A Former User

        Hi!

        I am not using any form or qml for design

        So, how do you render your text?

        PopQtP Offline
        PopQtP Offline
        PopQt
        wrote on last edited by
        #3

        @Wieland here is my code

            textWin = new QLabel(parent);
            textWin->setGeometry(xPos, yPos, widthWin, heightWin);
            textWin->setText("Welcome");// here i pass text
        

        I use this QLabel in many places and change the text according to my need. In some places I need subscript example: O2

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          QLabel supports a subset of HTML. You can use sub and sup tags:

          ui->label->setText("<sub>Low</sub>Normal<sup>High</sup>");
          

          PopQtP 1 Reply Last reply
          3
          • ? A Former User

            QLabel supports a subset of HTML. You can use sub and sup tags:

            ui->label->setText("<sub>Low</sub>Normal<sup>High</sup>");
            

            PopQtP Offline
            PopQtP Offline
            PopQt
            wrote on last edited by
            #5

            @Wieland
            But how should I declare ui

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              I just copy & pasted that from my editor, you don't need a ui object:

              textWin = new QLabel(parent);
              textWin->setGeometry(xPos, yPos, widthWin, heightWin);
              textWin->setText("<sub>Low</sub>Normal<sup>High</sup>");// here i pass text
              
              PopQtP 1 Reply Last reply
              1
              • ? A Former User

                I just copy & pasted that from my editor, you don't need a ui object:

                textWin = new QLabel(parent);
                textWin->setGeometry(xPos, yPos, widthWin, heightWin);
                textWin->setText("<sub>Low</sub>Normal<sup>High</sup>");// here i pass text
                
                PopQtP Offline
                PopQtP Offline
                PopQt
                wrote on last edited by
                #7

                @Wieland Thanks it worked. But I also need for color change for any particular alphabet. Could you help me

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by A Former User
                  #8

                  Same, you can use HTML:

                  setText("<sub><font color='purple'>Low</font></sub>Normal<sup><font color='orange'>High</font></sup>")
                  
                  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