1, Set font thickness
setFontWeight(int weight)
enum QFont::Weight Take the following values :

 

2, Set font italics
setFontItalic(bool italic)
true Indicates italics ,false It is not italicized .

 

3, Set underline
setFontUnderline(bool underline)
true Indicates an underline ,false nothing .

 

4, Set font type
setFontFamily(const QString & fontFamily)
 

5, Set font size
setFontPointSize(qreal s)
 

6, Set text color
setTextColor(const QColor & c)
 

7, Set text background color
setTextBackgroundColor(const QColor & c)
 

8, Set alignment
setAlignment(Qt::Alignment a)
Qt::Alignment The values are as follows :

Qt::AlignLeft Align left ,Qt::AlignRigh Right alignment ,Qt::AlignCenter Center alignment

 

     okay , There are too many methods , And it's very simple , Let's not list them one by one , Let's look at the main ones :

 

9, Insert picture :
void Widget::insertImage() { QImage image(":/Images/qq"); if (image.isNull())
return; int width = text_edit->viewport()->width(); int height =
text_edit->viewport()->height(); if (image.width() > width || image.height() >
height) { image = image.scaled(30, 30, Qt::KeepAspectRatio,
Qt::SmoothTransformation); } QTextCursor cursor = text_edit->textCursor();
QTextDocument *document = text_edit->document();
cursor.movePosition(QTextCursor::End);
document->addResource(QTextDocument::ImageResource, QUrl(":/Images/qq"),
QVariant(image)); // insert graphic images , use QTextCursor API file : QTextImageFormat image_format;
image_format.setName(":/Images/qq"); cursor.insertImage(image_format); }
     perhaps , use HTML Of img sign
 

10, Search for matching text to highlight
void Widget::search() { QString search_text = search_line_edit->text(); if
(search_text.trimmed().isEmpty()) { QMessageBox::information(this, tr("Empty
search field"), tr("The search field is empty.")); } else { QTextDocument
*document = text_edit->document(); bool found = false; QTextCursor
highlight_cursor(document); QTextCursor cursor(document); // start
cursor.beginEditBlock(); QTextCharFormat
color_format(highlight_cursor.charFormat());
color_format.setForeground(Qt::red); while (!highlight_cursor.isNull() &&
!highlight_cursor.atEnd()) { // find the specified text , Match whole word highlight_cursor =
document->find(search_text, highlight_cursor, QTextDocument::FindWholeWords);
if (!highlight_cursor.isNull()) { if(!found) found = true;
highlight_cursor.mergeCharFormat(color_format); } } cursor.endEditBlock(); // end
if (found == false) { QMessageBox::information(this, tr("Word not found"),
tr("Sorry,the word cannot be found.")); } } }

Technology
©2019-2020 Toolsou All rights reserved,
It's unexpected Python Cherry tree (turtle The gorgeous style of Library )Unity3D of UGUI Basics -- Three modes of canvas os Simple use of module computer network --- Basic concepts of computer network ( agreement , system )html Writing about cherry trees , Writing about cherry trees Some East 14 Pay change 16 salary , Sincerity or routine ?Unity-Demo Examples ✨ realization UI- Backpack equipment drag function 06【 Interpretation according to the frame 】 Data range filtering -- awesome java Four functional interfaces ( a key , simple )