日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

18.QT-QPlainEdit 信号与槽

發布時間:2023/12/10 c/c++ 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 18.QT-QPlainEdit 信号与槽 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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 <QWidget> #include <QPlainTextEdit> #include <QPushButton> #include <QDebug>class Widget : public QWidget {Q_OBJECTQPlainTextEdit 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

總結

以上是生活随笔為你收集整理的18.QT-QPlainEdit 信号与槽的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。