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. Possible to apply stylesheet to substring?

Possible to apply stylesheet to substring?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.4k 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.
  • TharronT Offline
    TharronT Offline
    Tharron
    wrote on last edited by
    #1

    Hi folks,

    I am curious if it is possible to apply a stylesheet or something similar to a part of a substring. I'll give an example to try to clarify my overall goal.

    I am building a menu system for an embedded product which will allow a user to modify some configuration parameters. I will not have a mouse/keyboard, but rather something like a simple keypad with L, R, Select. When I enter a sub-menu I may have up to 5 fields to modify. For example, changing the static IP Address would be 4 fields - 1 for each byte.

    I've got my hardware in place to allow me navigate everything just fine. Pressing select once will 'focus' that field and let you modify, and pressing again will de-focus. When not focused, you can scroll left and right to select which field you wish to modify next.

    The problem I am facing is how I can place some sort of visual emphasis on the focused field. Currently I have 5 QStrings which may or may not be used depending on which menu I'm in. I populate these based on the current saved configuration and concatentate them into a single QString which is then placed into my QLabel via setText().

    That works fine, and I can use an underline as the cursor, but as soon as I select a field on which to focus I cannot figure out a way to emphasize that focus. I'd be fine with a different color text, or inverted colors or anything like that, but I can't see a way to apply this to a substring within a single QLabel.

    Sorry for my rambling. Hopefully my thoughts are coherent enough to make some sense!

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Carmoneer
      wrote on last edited by Carmoneer
      #2

      I think I understand what you're asking, but I apologize if this isn't what you're looking for. Note, I have not tested this so I don't know if this will work, but:

      QLabel *label = new QLabel();
      
      if(label->hasFocus())
      {
           label->setText("<font color='red'>My text</font>");
      }
      

      Is that what you're trying to achieve?

      1 Reply Last reply
      1
      • TharronT Offline
        TharronT Offline
        Tharron
        wrote on last edited by Tharron
        #3

        Well, I feel silly.

        I was inserting the <u> tag without thinking I might be able to use other html-like tags such as <font>. I guess my new question is whether or not there is any sort of list of what I can or cannot use within a QString?

        edit Thanks Carmoneer! You wrote this up while I was smacking myself in the head for not thinking of doing this very thing earlier :-) That is exactly what I wanted to do.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Carmoneer
          wrote on last edited by
          #4

          Splendid! Glad to hear you were able to resolve your issue! As for that 'list' that you're seeking, one may exist, but I don't know of one. I just know of the good ol' handy-dandy QString Documentation :-) Cheers!

          1 Reply Last reply
          0
          • jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            What you are looking for is not related to QString. QString is just a string.
            Look here: http://doc.qt.io/qt-5/richtext-html-subset.html

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            TharronT 1 Reply Last reply
            1
            • jsulmJ jsulm

              What you are looking for is not related to QString. QString is just a string.
              Look here: http://doc.qt.io/qt-5/richtext-html-subset.html

              TharronT Offline
              TharronT Offline
              Tharron
              wrote on last edited by
              #6

              @jsulm said:

              What you are looking for is not related to QString. QString is just a string.
              Look here: http://doc.qt.io/qt-5/richtext-html-subset.html

              Ah hah! Thank you, this will be a big help for me!

              1 Reply Last reply
              0

              • Login

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