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


边栏推荐
- [redis realizes seckill service ④] one order for one person, and cannot be purchased repeatedly
- Leetcode 1248. Statistics of "graceful subarray" (harm, suddenly found that it can only enumerate violently)
- VNC viewer remote connection raspberry pie without display
- Qiniu cloud uploads video to get the first frame of video
- 2022年危险化学品经营单位安全管理人员考试试题及模拟考试
- 51单片机多机通信
- Databinding quick start (still using findviewbyid?)
- [microservices sentinel] sentinel quick start | building an image | starting the console
- [Solved] Public key for mysql-community-xxx. rpm is not installed
- Binder mechanism and Aidl communication example
猜你喜欢
最新QQ微信域名防红PHP程序源码+强制跳转打开

Decoupling pages and components using lifecycle

热力图展示相关矩阵
How to use promise Race() and promise any() ?

Practical operation notes - notebook plus memory and ash cleaning

51单片机多机通信

ros(24):error: invalid initialization of reference of type ‘xx’ from expression of type ‘xx’

Custom animation (simulated win10 loading animation) - Optimization

Binder mechanism and Aidl communication example

Virtual machine - network configuration
随机推荐
Custom animation (simulated win10 loading animation) - Optimization
Xcode预览(Preview)显示List视图内容的一个Bug及解决
2022 melting welding and thermal cutting recurrent training question bank simulated examination platform operation
Use coordinatorlayout+appbarlayout+collapsingtoolbarlayout to create a collapsed status bar
Mobile security tool -dex2jar
2022年危险化学品经营单位安全管理人员考试试题及模拟考试
Unimportant tokens can be stopped in advance! NVIDIA proposes an efficient visual transformer network a-vit with adaptive token to improve the throughput of the model
Infotnews | is the development of domestic NFT limited to digital collections?
Helm chart warehouse operation
Mobile security tool jarsigner
51单片机多机通信
断言(assert)的用法
Domain Driven Design and coding
Simple collation of Web cache
Thingsboard - rest API obtains and refreshes tokens
Custom animation (simulated win10 loading animation)
How to quickly open traffic master for wechat applet
百公里加速仅5.92秒,威兰达高性能版以高能产品实力领跑
不重要的token可以提前停止计算!英伟达提出自适应token的高效视觉Transformer网络A-ViT,提高模型的吞吐量!...
Qiniu cloud uploads video to get the first frame of video