您的位置:首页 > 编程语言 > Qt开发

Qt界面编程积累

2013-11-28 23:34 344 查看
1.QTextEdit类成员函数中包含了用于文本查找的成员函数,可用于“查找”对话框的设计:

bool QTextEdit::find(const QString & exp, QTextDocument::FindFlags options = 0)

Finds the next occurrence of the string, exp, using the given options. Returns true if exp was found and changes the cursor to select the match; otherwise returns false.

根据介绍可以知道该函数用于查询指定的exp字符串,如果找到了就将光标跳转到查找到的位置,如果没有找到就返回false。这个函数还有一个QTextDocument::FindFlags参数,可以看到该参数是一个枚举变量,用来指定查找的方式,分别是向后查找、区分大小写、全词匹配等。如果不指定该参数,默认的是向前查找、不区分大小写、包含该字符串的词也可以查找到。这几个变量还可以使用“|”符号来一起使用。

2.QTextEdit类可以通过如下方法获取文本是否被编辑过:textEdit->document()->isModified();可以用于文本保存前的判断。

3.在进行较长时间工作时可通过如下方法掩饰界面的暂时无响应状态

QApplication::setOverrideCursor(Qt::WaitCursor);

out << ui->textEdit->toPlainText();

// 鼠标指针恢复原来的状态

QApplication::restoreOverrideCursor();
对QApplication的setOverideCursor函数解释如下:

voidQGuiApplication::setOverrideCursor(const
QCursor & cursor) [static]

Sets the application override cursor to cursor.

Application override cursors are intended for showing the user that the application is in a special state, for example during an operation that might take some time.

This cursor will be displayed in all the application's widgets until restoreOverrideCursor() or another setOverrideCursor() is called.

Application cursors are stored on an internal stack. setOverrideCursor() pushes the cursor onto the stack, and restoreOverrideCursor() pops the active cursor off the stack. changeOverrideCursor() changes the curently active application override cursor.

Every setOverrideCursor() must eventually be followed by a corresponding restoreOverrideCursor(), otherwise the stack will never be emptied.

可以看出QCoursor是Qt为显示光标定义的一个类,可以使用这个类进行自定义光标显示。

4.在Qt中,通过调用QApplication::clipboard()静态函数可以使用系统剪贴板,通过调用QClipboard::setText()就既可以在本应用程序中又可以在其他应用程序中使用放在剪贴板上的这些文本。再次使用QClipboard::text()函数就可获得放在剪贴板中的内容。

这里要注意的一个细节是对剪切可以看做是复制操作再加上一个删除操作。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: