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



  • 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..



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.