博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
18.QT-QPlainEdit 信号与槽
阅读量:5126 次
发布时间:2019-06-13

本文共 3437 字,大约阅读时间需要 11 分钟。

QPlainEdit编辑功能

Public Slots

void appendHtml ( const QString & html )void appendPlainText ( const QString & text )void centerCursor ()void clear ()void copy ()void cut ()void insertPlainText ( const QString & text )void paste ()void redo ()void selectAll ()void setPlainText ( const QString & text )void undo ()

Signals

void blockCountChanged ( int newBlockCount );//每当按下回车或者删除回车(更新字符块),则newBlockCount计数,并触发该信号, newBlockCount 默认为1void copyAvailable ( bool yes );//选择某串文字时,则触发该信号,并设置yes为true,如果取消选择,也会触发该信号,设置 yes为falsevoid cursorPositionChanged ()////每当光标的位置发生变化时,触发该信号void redoAvailable ( bool available );//当文本框为空,则会触发该信号,并设置available为false,因为该文本框没有数据,所以无法重做//当用户向空文本框输入数据时,同样也会触发该信号,设置available为true,表示可以实现重做void selectionChanged ();//当鼠标点击文本框时,触发该信号void textChanged ();//每当文档的内容发生变化时,则触发该信号,可以用来判断输入的字符是什么 void undoAvailable ( bool available );//当用户无法撤销时,便会触发该信号,并设置available为false//当用户修改/写入文本框内容,便会触发该信号,并设置available为true,表示可以撤销

 

 

示例代码

Widget.h:

#ifndef WIDGET_H#define WIDGET_H#include 
#include
#include
#include
class Widget : public QWidget{ Q_OBJECT QPlainTextEdit edit; QPushButton* Undo; QPushButton* Redo; QPushButton* Cut; QPushButton* Copy; QPushButton* Paste; QPushButton* all; QPushButton* clear;private slots: void oncopyAvailable ( bool yes ); void onredoAvailable ( bool available ); void onundoAvailable ( bool available );public: explicit Widget(QWidget *parent = 0);};#endif

 

Widget.c:

#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

你可能感兴趣的文章
倒挤法
查看>>
允许物料批改
查看>>
FAQ About WOYO PDR007 Dent Removal Heat Induction System
查看>>
2016 New Mercedes Benz SD Connect C5 Better Quality Tested Great
查看>>
Why Launch X431 PRO MINI Bluetooth better than Diagun 3
查看>>
2017 Launch X431 Pro Mini review – newer & better than many tools
查看>>
Porsche Piwis Tester II V15.6 with CF30 Laptop or Lenovo E49AL Laptop
查看>>
MB Star C5 Xentry Connect Mercedes Benz SD Connect C5 Enhanced than Mercedes sds C4 scanner
查看>>
How to Connect Caterpillar ET Software from your Laptop to ECM
查看>>
Xtool x100 pad2 FAQS and the solutions for software cant working
查看>>
XTOOL X100 Pad2 Read Peugeot 206 BSI Pin Code Test Report
查看>>
FAQ about MB STAR C4, MB STAR C5 Update
查看>>
John Deere Service Advisor 5.2.467 2019 Agriculture Equipment Division
查看>>
MB Star C6 Benz Diagnostic Tool with DOIP&AUDIO Function
查看>>
Service Advisor John Deere Software
查看>>
rpm命令
查看>>
取IP地址的几种方法
查看>>
替换多个文件关键字的方法
查看>>
echo的一些参数
查看>>
文件和目录权限相关命令
查看>>