zoukankan      html  css  js  c++  java
  • 18.QT-QPlainEdit 信号与槽

    #include "Widget.h"
    
    Widget::Widget(QWidget *parent) :
        QWidget(parent),
        edit(this)
    {
        edit.setGeometry(0,0,280,300);
    
        Undo=new QPushButton("重做",this);
        Redo=new QPushButton("撤销",this);
        Cut=new QPushButton("剪切",this);
        Copy=new QPushButton("复制",this);
        Paste=new QPushButton("拷贝",this);
        all=new QPushButton("全选",this);
        clear=new QPushButton("删除",this);
        Undo->setGeometry(290,0,100,30);
        Redo->setGeometry(290,40,100,30);
        Cut->setGeometry(290,80,100,30);
        Copy->setGeometry(290,120,100,30);
        Paste->setGeometry(290,160,100,30);
        all->setGeometry(290,200,100,30);
        clear->setGeometry(290,240,100,30);
        Undo->setEnabled(false);
        Redo->setEnabled(false);
        Cut->setEnabled(false);
        Copy->setEnabled(false);
    
        
        connect(Undo, SIGNAL(clicked()) , &edit ,SLOT(undo()));
        connect(Redo, SIGNAL(clicked()) ,  &edit ,SLOT(redo()));
        connect(Cut, SIGNAL(clicked()) ,    &edit ,SLOT(cut()));
        connect(Copy, SIGNAL(clicked()) ,    &edit ,SLOT(copy()));
        connect(Paste, SIGNAL(clicked()) ,    &edit ,SLOT(paste()));
        connect(all, SIGNAL(clicked()) ,  &edit ,SLOT(selectAll()));
        connect(clear, SIGNAL(clicked()) ,  &edit ,SLOT(clear()));
    
        
        connect(&edit, SIGNAL(copyAvailable(bool)) , this ,SLOT(oncopyAvailable(bool)));
        connect(&edit, SIGNAL(redoAvailable(bool)) , this ,SLOT(onredoAvailable(bool)));
        connect(&edit, SIGNAL(undoAvailable(bool)) , this ,SLOT(onundoAvailable(bool)));
        connect(&edit, SIGNAL(selectionChanged()) , this ,SLOT(onselectionChanged()));
    
    }
    
    void    Widget::oncopyAvailable ( bool yes )
    {
           Cut->setEnabled(yes);
           Copy->setEnabled(yes);
    }
    
    void    Widget::onredoAvailable( bool available )
    {
           Redo->setEnabled(available);
    }
    
    void    Widget::onundoAvailable ( bool available )
    {
           Undo->setEnabled(available);
    }

    文章来源:https://www.cnblogs.com/lifexy/p/9003918.html

  • 相关阅读:
    Go语言对etcd的基本操作
    etcd命令行基本操作
    etcd集群部署
    第二十一天python3 python的正则表达式re模块学习
    第二十天python3 正则表达式
    jenkins多分支构建选择
    第十九天python3 json和messagepack
    华为交换机设置ntp时间同步
    交换机端口光衰问题排查
    第十八天python3 序列化和反序列化
  • 原文地址:https://www.cnblogs.com/xiongjim/p/9673928.html
Copyright © 2011-2022 走看看