4.每天学点qt -----QTextedit
2020-04-05 07:24
1311 查看
//slots 解析
void append ( const QString & text ) //追加文本文档到文本框 void clear () //清除文本框的所有内容 void copy () //拷贝 使用这个首先前置条件为 selectAll() void cut () //剪切 使用这个首先前置条件为 selectAll() void insertHtml ( const QString & text ) //插入html代码 void insertPlainText ( const QString & text ) //插入纯文本 void paste () //粘贴 void redo () //重做 void scrollToAnchor ( const QString & name ) void selectAll () //选择文本框的所有内容 void setAlignment ( Qt::Alignment a ) //改变文本对齐的方式 //下方的是setAlignment中的要填写的一些内容 Constant Value Description Qt::AlignLeft 0x0001 Aligns with the left edge. Qt::AlignRight 0x0002 Aligns with the right edge. Qt::AlignHCenter 0x0004 Centers horizontally in the available space. Qt::AlignJustify 0x0008 Justifies the text in the available space. void setCurrentFont ( const QFont & f ) //设置自体 void setFontFamily ( const QString & fontFamily )//设置文字字体 void setFontItalic ( bool italic ) //设置文字是否为斜体 void setFontPointSize ( qreal s ) //设置字体大小 void setFontUnderline ( bool underline ) //设置是否有下划线 void setFontWeight ( int weight ) //设置文字粗细//enum Weight 存在5个值 void setHtml ( const QString & text ) //设置html内容 void setPlainText ( const QString & text ) //设置纯文本 void setText ( const QString & text ) //可以设置一些例如html的 void setTextBackgroundColor ( const QColor & c ) //设置背景颜色 void setTextColor ( const QColor & c ) //设置字体颜色 void zoomOut ( int range = 1 ) //实现放大
//
void copyAvailable ( bool yes ) ////选择某串文字时,则触发该信号,并设置yes为true,如果取消选择,也会触发该信号,设置 yes为false void currentCharFormatChanged ( const QTextCharFormat & f ) //每当按下回车或者删除回车(更新字符块),则newBlockCount计数,并触发该信号, newBlockCount 默认为1 void cursorPositionChanged ()////每当光标的位置发生变化时,触发该信号 void redoAvailable ( bool available ) ///当文本框为空,则会触发该信号,并设置available为false,因为该文本框没有数据,所以无法重做//当用户向空文本框输入数据时,同样也会触发该信号,设置available为true,表示可以实现重做 void selectionChanged () //当鼠标点击文本框时,触发该信号 void textChanged () //文本框的文字被改变的时候 void undoAvailable ( bool available ) //当用户无法撤销时,便会触发该信号,并设置available为false //当用户修改/写入文本框内容,便会触发该信号,并设置available为true,表示可以撤销
#ifndef WIDGET_H #define WIDGET_H #include <QWidget> #include <QPlainTextEdit> #include <QPushButton> #include <QDebug> 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
#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); }
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- QT自动下载网页每天更新的文件
- Qt学习之路之 QTextEdit 重温
- Qt使用QTextEdit进行文本编辑实现查找高亮
- Qt 文本框类QLineEdit和QTextEdit
- Qt 5.6 QMessageBox 按钮显示为中文及 QTextEdit右键显示中文
- Qt 对QTextEdit的文本编辑器进行查找操作
- Qt中的QLineEdit、QTextEdit和QPla…
- Lomper 每天进步一点点~~ QT学习之QString的arg方法
- QT-Qtextedit设置光标位置
- 【Qt开发】QTextEdit 外观属性设置
- Qt___QTextEdit____操作
- QT-QTextedit获得行数以及列数
- qt中qlineedit和qtextedit右键菜单翻译成中文
- Qt - QTextEdit
- Qt入门-文本框类QLineEdit和QTextEdit
- qt5把qt_zh_CN.qm加载了,但QTextEdit的右键菜单仍然是英文,而QLineEdit的倒是中文。怎样设置使得QTextEdit的右键菜单是中文
- 【QT】QT从零入门教程(八):QT常用控件 [QLabel、QPushButton、QLineEdit、QTextEdit]
- Qt入门-文本框类QLineEdit和QTextEdit
- Qt入门-文本框类QLineEdit和QTextEdit
- 自学qt之新建菜单,文件 QtextEdit 打开保存文件 设置字体