当前位置:网站首页>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 :


边栏推荐
- 【微服务|Sentinel】实时监控|RT|吞吐量|并发数|QPS
- Xcode preview displays a bug in the content of the list view and its solution
- The acceleration of 100 km is only 5.92 seconds, and the willanda high-performance version leads with the strength of high-energy products
- QT(35)-操作EXCEL-QXlsx-QAxObject
- 2021-09-12
- I brush the question I - copy the linked list with random pointer
- Sliding window technology based on byte in transport layer
- 51单片机多机通信
- 2022年全国最新消防设施操作员(高级消防设施操作员)模拟题及答案
- Hot fix sophix multi-channel patch solution
猜你喜欢

Usage of ViewModel and livedata in jetpack

2022安全员-C证考试模拟100题及在线模拟考试
最新QQ微信域名防红PHP程序源码+强制跳转打开

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

Custom animation (simulated win10 loading animation) - Optimization

2022年全国最新消防设施操作员(高级消防设施操作员)模拟题及答案

Wallpaper applet wechat applet

If the order has not been paid for 30 minutes, it will be automatically cancelled. How can I achieve this?
Outer screen and widescreen wasted? Harmonyos folding screen design specification teaches you to use it

Easy to wear - drop down radio
随机推荐
Input series
2022熔化焊接与热切割复训题库模拟考试平台操作
2021-04-18
Working principle analysis of kubernetes architecture core components
Eliminate duplicate dependencies
不重要的token可以提前停止计算!英伟达提出自适应token的高效视觉Transformer网络A-ViT,提高模型的吞吐量!...
2022R1快开门式压力容器操作考题及答案
[redis realizes seckill service ④] one order for one person, and cannot be purchased repeatedly
Xcode预览(Preview)显示List视图内容的一个Bug及解决
2022年起重机司机(限桥式起重机)考试题库模拟考试平台操作
Source code analysis the problem that fragments cannot be displayed in the custom ViewGroup
The picture of wechat official account can not be displayed normally
Several ways for wechat applet to jump to the page are worth collecting
2022年危险化学品经营单位安全管理人员考试试题及模拟考试
Infotnews | is the development of domestic NFT limited to digital collections?
Tiktok wallpaper applet v1.0.2 function, new arrival function
Leetcode 1248. Statistics of "graceful subarray" (harm, suddenly found that it can only enumerate violently)
Qiniu cloud uploads video to get the first frame of video
Realization of MNIST handwritten numeral recognition
How to reduce the font size of custom controls (optimize the round dot progress bar)