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. QTextEdit Check if selected section is bold

QTextEdit Check if selected section is bold

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.5k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    adviner
    wrote on last edited by
    #1

    I have a bold button that when selected can set the text and make it bold as follows:

    QTextCursor cursor = this->ui->editNotes->textCursor();
    QTextCharFormat format;
    format.setFontWeight(QFont::Bold);
    cursor.mergeCharFormat(format);
    The question is how to press the same bold button and check if the selected text is bold? So if its already bold i will remove the bold from the same selection. Do I have to parse the html code? Example if I look at the text that I made bold the html data has the following span. I have to break it up cause when i post the html it gets removed:

    span
    style
    font-family:'Arial,Helvetica';
    font-size:14px;
    font-weight:600; color:#313131;
    Data between the span: functions

    Is there an easier method then parsing the attributes the text is wrapped in to check the font-weight? Or is this the only solution?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      adviner
      wrote on last edited by
      #2

      Anyone ? Im sure someone has attempted this or ran into this before. I guess I want to know if their is an qt api or if I would need to parse it myself. Really its more than checking if its bold. It can be if its italic or underline, etc. I have a strong feeling that I will have to parse it myself. But before I go that route I want to make sure their is no qt api

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andreyc
        wrote on last edited by
        #3

        I see two ways to do it

        Keep track of all text pieces like letters, words, sentences, etc. That way you will know everything and you will be able to find the changes quickly. But it will take some memory.

        Don't track and find all changes on a fly like you described. Less memory usage but more time to process.

        Also you can combine both methods.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          adviner
          wrote on last edited by
          #4

          @andreyc thanks for the feedback. I'm thinking that the second option may make the best sense. Thanks for the tip

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andreyc
            wrote on last edited by
            #5

            You are welcome.
            You may consider "QXml....":http://qt-project.org/doc/qt-5/qtxml-module.html classes to keep your document. Maybe it will make easier to search.

            [EDIT]: Scratch my suggestion about QXml... I did not realize that you using QText... class.

            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