Ok. I just tried a way. But you need to do tweak in a little bit for total functionality.
connect the signal slot,
connect(ui.textEdit, SIGNAL(copyAvailable(bool)), this, SLOT(formatText(bool)));
connect(ui.textEdit, SIGNAL(copyAvailable(bool)), this, SLOT(formatText(bool)));
To copy to clipboard, switch view to plain text mode
and slot goes like this
void samplewidget::formatText(bool bSelectState)
{
if(!bSelectState)
return;
ui.textEdit->copy();
QString sFullString
= ui.
textEdit->toPlainText
();
int pos = ui.textEdit->textCursor().position();
pos -= str.length();
QString str1
= "<html><b>" + str
+ "</b></html>";
sFullString.replace(pos, str.length(), str1);
ui.textEdit->setText(sFullString);
}
void samplewidget::formatText(bool bSelectState)
{
if(!bSelectState)
return;
ui.textEdit->copy();
QClipboard* pClip = QApplication::clipboard();
QString str = pClip->text(QClipboard::Clipboard);
QString sFullString = ui.textEdit->toPlainText();
int pos = ui.textEdit->textCursor().position();
pos -= str.length();
QString str1 = "<html><b>" + str + "</b></html>";
sFullString.replace(pos, str.length(), str1);
ui.textEdit->setText(sFullString);
}
To copy to clipboard, switch view to plain text mode
Bookmarks