当前位置:网站首页>Rich text tables, lists, pictures
Rich text tables, lists, pictures
2022-06-25 01:02:00 【PureヾChan】
One 、 To create mianWindows.h Add slot function
private slots:
void insertTable();// Insert table
void insertList();// Insert the list
void insertImage();// Insert a picture Function implementation :
void MainWindow::insertTable()
{
//QTextDocument* document=ui->textEdit->document();// Returns the text object of the current editing area
QTextCursor cursor=ui->textEdit->textCursor();
QTextTableFormat format;// Define a table format object
format.setCellSpacing(2);// Set the outer distance
format.setCellPadding(10);// Set the inner margin of the table
cursor.insertTable(3,3,format);// Create a self - defined 3 That's ok 3 List grid style
}
void MainWindow::insertList()
{
QTextListFormat format;
format.setStyle(QTextListFormat::ListDecimal);// The linked list format is set to the form of digital linked list
ui->textEdit->textCursor().insertList(format);// Put the text linked list format into the settings
}
void MainWindow::insertImage()
{
QString filepath=QFileDialog::getOpenFileName(this,
" Select Picture ",
".",
"JPGE(*.jpg *jpeg);;"
"GIF(*.gif);;"
"PNG(*.png)");
QUrl url(QString("file:://%1").arg(filepath));
QImage image=QImageReader(filepath).read();
QTextDocument* document=ui->textEdit->document();
// When adding picture resources
document->addResource(QTextDocument::ImageResource,url,QVariant(image));
QTextCursor cursor=ui->textEdit->textCursor();
QTextImageFormat imageFormat;
imageFormat.setWidth(image.width());
imageFormat.setWidth(image.height());
imageFormat.setName(url.toString());
cursor.insertImage(imageFormat);
}
insertTable The function first defines a cursor , Get the text information of the current cursor . Defining a table format object ,format Set the outer and inner margins . recycling insertTable Cursor object function , Realize custom formatting , The first and second parameters are rows and columns , The third parameter is format .
insertList Function is to define a linked list format object , Using style Function to set the format to the format of the number linked list , Call next textCusor Function to get cursor information , Calling insertList Function to truly set the linked list format of the text editing area .
insertImage Function is to call the file box function to get the path name of the file , recycling Qurl Define an object , Transfer the file name to encoded form .
Then define a QImage Object utilization QImageReader Function to read pictures . Then use the obtained text object document Add resources . The next step is to format the image .
mianWindows Add code to the constructor of :
// Add table 、 list 、 Add images Action
QAction *action_textTable=new QAction(" form ",this);
QAction *action_textList=new QAction(" Linked list ",this);
QAction *action_textImage=new QAction(" picture ",this);
connect(action_textTable,&QAction::triggered,this,&MainWindow::insertTable);
connect(action_textList,&QAction::triggered,this,&MainWindow::insertList);
connect(action_textImage,&QAction::triggered,this,&MainWindow::insertImage);
// Toolbar add button
ui->mainToolBar->addAction(action_textTable);
ui->mainToolBar->addAction(action_textList);
ui->mainToolBar->addAction(action_textImage);
Create a connection between the three parts and their own defined slot function , Click to trigger implementation .
Program effect :

边栏推荐
- ros(25):rqt_ image_ View reports an error unable to load plugin for transport 'compressed', error string
- How to quickly open traffic master for wechat applet
- ros(24):error: invalid initialization of reference of type ‘xx’ from expression of type ‘xx’
- Decoupling pages and components using lifecycle
- Simulation questions and answers of the latest national fire facility operator (senior fire facility operator) in 2022
- 2022熔化焊接与热切割复训题库模拟考试平台操作
- I'd like to ask how to open an account at industrial securities? Is it safe to open a stock account through the link
- 实现mnist手写数字识别
- More pictures | explain the Nacos parameters in detail!
- Eliminate duplicate dependencies
猜你喜欢

Use of navigation and navigationui

2021-11-07

【微服务|Sentinel】Sentinel快速入门|构建镜像|启动控制台

Custom animation (simulated win10 loading animation)

Custom animation (simulated win10 loading animation) - Optimization

Thermodynamic diagram display correlation matrix

QT(35)-操作EXCEL-QXlsx-QAxObject

2022 melting welding and thermal cutting recurrent training question bank simulated examination platform operation

In the process of enterprise development, I found that a colleague used the select * from where condition for update

2022R1快开门式压力容器操作考题及答案
随机推荐
我想问一下兴业证券怎么开户?通过链接办理股票开户安全吗
生成订单30分钟未支付,则自动取消,该怎么实现?
Uniapp encapsulated incentive advertisement, screen insert advertisement and banner advertisement
Apk slimming compression experience
The picture of wechat official account can not be displayed normally
A small program written this week
[Solved] Public key for mysql-community-xxx. rpm is not installed
2022R1快开门式压力容器操作考题及答案
ros(25):rqt_image_view报错Unable to load plugin for transport ‘compressed‘, error string
I 刷题 I — 复制带随机指针的链表
移动安全工具-apktool
redis + lua实现分布式接口限流实现方案
51单片机多机通信
2021-04-18
Only positive integers can be entered in the text box
Registration method of native method in JNI
Xcode preview displays a bug in the content of the list view and its solution
Source code analysis the problem that fragments cannot be displayed in the custom ViewGroup
EVM Brief
More pictures | explain the Nacos parameters in detail!