当前位置:网站首页>Text editor for QT project practice - Episode 12
Text editor for QT project practice - Episode 12
2022-06-25 01:00:00 【PureヾChan】
The previous implementation of the document text and paragraph operation , Next, we are going to print documents and preview them .
Document printing implementation :
towards mainWindow.h Add function :
public:
void docPrint();// Document printing
private slots:
void on_printAction_triggered();Slot function on_PrintAction_triggered() A function is to call docPrint() function .
Function implementation :
void MainWindow::docPrint()
{
// Printing, of course, requires a printer
QPrinter pter(QPrinter::HighResolution);// Set the printer's pixels
// With a print rack, of course, there must be a print dialog
QPrintDialog *ddlg=new QPrintDialog(&pter,this);
if(activateChildWnd()){
ddlg->setOption(QAbstractPrintDialog::PrintSelection,true);
}
ddlg->setWindowTitle(" Print the document ");
// Save the currently active child window
ChildWnd *childWnd=activateChildWnd();
if(ddlg->exec()==QDialog::Accepted){
childWnd->print(&pter);
}
delete ddlg;
}
void MainWindow::on_printAction_triggered()
{
docPrint();
}
The printing function of course requires a printer , When defining the function, first define a printer specified pixel . Print, then there must be a print prompt box , Define a QPrintDialog object , And then judge whether it is an active window , If yes, set the options of the print prompt box to user selectable . Then get the current active window , Determine whether to accept printing by mode , Accept print call sub window QTextEdit Print function for print, Then delete the text print box you created .
Print preview implementation :
mainWindow.h Add function :
public:
void docPrintPreview();// Print preview
private slots:
void printPreview(QPrinter*printer);
void on_printPreviewAction_triggered();Function implementation :
void MainWindow::docPrintPreview()
{
QPrinter pter;
QPrintPreviewDialog preview(&pter,this);
connect(&preview,SIGNAL(paintRequested(QPrinter*)),
this,SLOT(printPreview(QPrinter*)));
preview.exec();
}
void MainWindow::printPreview(QPrinter *printer)
{
activateChildWnd()->print(printer);
}
void MainWindow::on_printPreviewAction_triggered()
{
docPrintPreview();
}The main idea is to call the click slot function when clicking print preview in the main window , Click the slot function and call print preview docPrint function , First, define a printer , Because the print preview dialog box will use . In establishing signals and slots , If there is a printing demand , Just call printPreview function , To realize printing .
Program effect :


边栏推荐
- placeholder
- 5-minute NLP: summary of 3 pre training libraries for rapid realization of NER
- 百公里加速仅5.92秒,威兰达高性能版以高能产品实力领跑
- Examination questions and mock examination for safety management personnel of hazardous chemical business units in 2022
- Golang示例续期锁:Redis+Channel+sync.Mutex
- What is test development? Can you find a job at this stage?
- A plug-in framework for implementing registration free and login verification with hook technology
- If the order has not been paid for 30 minutes, it will be automatically cancelled. How can I achieve this?
- 2021-02-15
- Technologie des fenêtres coulissantes en octets dans la couche de transmission
猜你喜欢

A small program written this week

Single blind box removal, social blind box and friend blind box program source code

Using tcp/udp tools to debug the yeelight ribbon

Apk decompiled method (not confused)

Sliding window technology based on byte in transport layer

Tiktok wallpaper applet, starlight wallpaper applet version 2.0, upgraded version

2022年起重机司机(限桥式起重机)考试题库模拟考试平台操作
Paper review: U2 net, u-net composed of u-net

傳輸層 以字節為單比特的滑動窗口技術

Punch smart spirit 1. The brand is attractive. What is the strength of the product?
随机推荐
The interview questions and answers for the high-frequency software test of Dachang help you prepare for the golden nine silver ten
打卡smart精灵#1,品牌不缺吸引力,产品本身实力如何?
Paint rounded rectangle
Some examples of MgO operating database in go
Sanic服务启动失败
December 6, 2019 what happens after the browser enters a URL
VNC viewer remote connection raspberry pie without display
Qiniu cloud uploads video to get the first frame of video
The problem of multiple callback of video ads stimulated by applets (offcolse problem)
【Redis实现秒杀业务③】超卖问题之乐观锁具体实现
Mobile security tool apktool
2022年危险化学品经营单位安全管理人员考试试题及模拟考试
C# 闭包的垃圾回收
移动安全工具-apktool
redis + lua实现分布式接口限流实现方案
Use of navigation and navigationui
Leetcode 1248. Statistics of "graceful subarray" (harm, suddenly found that it can only enumerate violently)
Kibana installation via kubernetes visual interface (rancher)
[Solved] Public key for mysql-community-xxx. rpm is not installed
If the order has not been paid for 30 minutes, it will be automatically cancelled. How can I achieve this?