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. [SOLVED] how to get html bold to be inserted beside the selected word?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] how to get html bold to be inserted beside the selected word?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.0k 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.
  • K Offline
    K Offline
    kalster
    wrote on last edited by
    #1

    In the textedit, when the user selects the word and then clicks the bold button, i need the <b> and </b> to be inserted beside the word. in the text below, the bold works but not correctly the way i would want it because the <b> and </b> is not inserted beside the word and i don't need the word highlighted. can i have an example please?

    @void MainWindow::on_pushButton_clicked()
    {
    if (ui->sayLineEdit->fontWeight() == QFont::Bold)
    ui->sayLineEdit->setFontWeight(QFont::Normal);
    else
    ui->sayLineEdit->setFontWeight(QFont::Bold);
    }@

    i searched the docs and found that selectedText() might work in this case but i am getting an error that textCursor() was not declared. how to declare it, and could i also get some help for my first question above please. thank you in advanced.

    @QString TextEdit::textUnderCursor () const
    {
    QTextCursor tc = textCursor ();
    tc.select (QTextCursor::WordUnderCursor);
    return tc.selectedText ();
    }@@

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Add this at the top of your file:

      @
      #include <QTextCursor>
      @

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kalster
        wrote on last edited by
        #3

        i added the include but i still get an error 'textCursor' was not declared in this scope

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kalster
          wrote on last edited by
          #4

          i solved the textCursor issue. textCursor() should have been ui->textEdit->textCursor(). the selectedText() i can use to make the bold.

          this topic is solved.

          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