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,
@Repository The role of annotations Conflict statement (conflicting declaration) solve iPhone 12 price , Configure full exposure : Cut it off 64GB, Battery 2227mAh start 【Python- data fetch 】 read txt Each line of file generates a list of data TypeScript Data types in is enough Mybatis Mapping file Mapper.xml in # and $ The difference between uboot set up nfs parameter ——linux kernel use nfs Mode to load the root file system rootfs( Six )( Essence )2020 year 6 month 26 day C# Class library read json Profile help class python Short circuit logic in ( Essence )2020 year 8 month 2 day TypeScript The use of generics