当前位置:网站首页>Text editor of QT project practice ---------- episode 8

Text editor of QT project practice ---------- episode 8

2022-06-25 00:59:00 PureヾChan

In the last episode, we implemented the operation of saving documents , This episode , We need to implement some operations on the text of the document , If revoked , rewrite , shear , Copy , Paste and so on .

towards mainWindow.h Add function :

   
public:
    void docUndo();// revoke 
    void docRedo();// rewrite 
    void docCut();// shear 
    void docCopy();// Copy 
    void docPaste();// Paste 

The above function definition :

void MainWindow::docUndo()
{
    if(activateChildWnd()){
        activateChildWnd()->undo();
    }
}

void MainWindow::docRedo()
{
    if(activateChildWnd()){
        activateChildWnd()->redo();
    }
}

void MainWindow::docCut()
{
    if(activateChildWnd()){
        activateChildWnd()->cut();
    }
}

void MainWindow::docCopy()
{
    if(activateChildWnd()){
        activateChildWnd()->copy();
    }
}

Whether it is to undo or rewrite some column operations , In fact, they are all documents, that is QTextEdit Class . And we actually create these functions for , With the main window Action Establish the link between signal and slot .

For cancellation, etc Action Create slot functions :

private slots:
 
void on_undoAction_triggered();

    void on_redoAction_triggered();

    void on_cutAction_triggered();

    void on_copyAction_triggered();

    void on_pasteAction_triggered();

Function definition :

void MainWindow::on_undoAction_triggered()
{
    docUndo();
}

void MainWindow::on_redoAction_triggered()
{
    docRedo();
}

void MainWindow::on_cutAction_triggered()
{
    docCut();
}

void MainWindow::on_copyAction_triggered()
{
    docCopy();
}

void MainWindow::on_pasteAction_triggered()
{
    docPaste();
}

The slot function automatically calls the function implemented in the main window when clicking . In this way, you can undo the text window , rewrite , shear , Copy , Paste a series of operations .

 

原网站

版权声明
本文为[PureヾChan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202210545037105.html