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. Problem in not getting BOLD format in QTextEdit using tohtml()

Problem in not getting BOLD format in QTextEdit using tohtml()

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

    Hi All,
    Actually , my task is to make bold on the selected text on QTextEdit ..
    and finally i will be storing the QtextEdit text to a file with html format.

    Later ..when i do open my application , i will be populating the content back from File to QtextEdit value...but the format is not bold...which it should be..
    my codes are:
    @
    void CTestDlg::boldButtonPressed()
    {
    QTextCharFormat fmt;

    QTextCursor cursor = ui->textEdit->textCursor();
    
    if (!cursor.hasSelection())
        cursor.select(QTextCursor::WordUnderCursor);
    
    if( cursor.charFormat().fontWeight() == QFont::Bold  )
        fmt.setFontWeight( QFont::Normal);
    else
    {
       fmt.setFontWeight( QFont::Bold);
    }
    
    
    cursor.mergeCharFormat( fmt );
    
    qDebug()<<"cursor.selectedText()*******************"<<cursor.selectedText();
    
    ui->textEdit->mergeCurrentCharFormat(fmt);
    

    }

    void CtestDlg::saveToFile()
    {

    QString strText = ui->textEdit->tohtml();
    //then storing this string value into a file..
    }

    void CTestDlg::readFromFile()
    {
    QString strText = readFile();// here i am reading exactly..what has been stored in the file
    ui->textedit->settext( strText );
    }
    @

    Please let me know..whether i am doing anything wrong on this..

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

      Th code works for me. What's the content of the file?

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

      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