There is a QTextEdit, and how to make selected text as Bold?
P.S. Sorry for probable mistakes in the text.
There is a QTextEdit, and how to make selected text as Bold?
P.S. Sorry for probable mistakes in the text.
use html tags while setting a text.
textEdit->setText("<html><b>Hello</b</html>");
go through QtAssistant, checkout "QTextEdit Class".
I use textCursor() method for return selected text and then I don't know what to do with it
In documentation I found QTextFormat Class, but i don't understand how to use it..
I found an example in the documentation:
QTextDocument *document = edit->document();
QTextCursor cursor(document);
cursor.movePosition(QTextCursor::Start);
cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
QTextCharFormat format;
format.setFontWeight(QFont::Bold);
cursor.mergeCharFormat(format);//do the text as Bold
Ok. I just tried a way. But you need to do tweak in a little bit for total functionality.
connect the signal slot,
and slot goes like thisQt Code:
connect(ui.textEdit, SIGNAL(copyAvailable(bool)), this, SLOT(formatText(bool)));To copy to clipboard, switch view to plain text mode
Qt Code:
void samplewidget::formatText(bool bSelectState) { if(!bSelectState) return; ui.textEdit->copy(); int pos = ui.textEdit->textCursor().position(); pos -= str.length(); sFullString.replace(pos, str.length(), str1); ui.textEdit->setText(sFullString); }To copy to clipboard, switch view to plain text mode
This is the code that is easy for me.
Qt Code:
QTextCharFormat format; ui->plainTextEdit->textCursor().mergeCharFormat(format);To copy to clipboard, switch view to plain text mode
Bookmarks