本文整理汇总了C++中QPlainTextEdit::ensureCursorVisible方法的典型用法代码示例。如果您正苦于以下问题:C++ QPlainTextEdit::ensureCursorVisible方法的具体用法?C++ QPlainTextEdit::ensureCursorVisible怎么用?C++ QPlainTextEdit::ensureCursorVisible使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPlainTextEdit
的用法示例。
在下文中一共展示了QPlainTextEdit::ensureCursorVisible方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sinkMessage
void MessagesDialog::sinkMessage( const MsgEvent *msg )
{
QMutexLocker locker( &messageLocker );
QPlainTextEdit *messages = ui.messages;
/* Only scroll if the viewport is at the end.
Don't bug user by auto-changing/losing viewport on insert(). */
bool b_autoscroll = ( messages->verticalScrollBar()->value()
+ messages->verticalScrollBar()->pageStep()
>= messages->verticalScrollBar()->maximum() );
/* Copy selected text to the clipboard */
if( messages->textCursor().hasSelection() )
messages->copy();
/* Fix selected text bug */
if( !messages->textCursor().atEnd() ||
messages->textCursor().anchor() != messages->textCursor().position() )
messages->moveCursor( QTextCursor::End );
/* Start a new logic block so we can hide it on-demand */
messages->textCursor().insertBlock();
QString buf = QString( "<i><font color='darkblue'>%1</font>" ).arg( msg->module );
switch ( msg->priority )
{
case VLC_MSG_INFO:
buf += "<font color='blue'> info: </font>";
break;
case VLC_MSG_ERR:
buf += "<font color='red'> error: </font>";
break;
case VLC_MSG_WARN:
buf += "<font color='green'> warning: </font>";
break;
case VLC_MSG_DBG:
default:
buf += "<font color='grey'> debug: </font>";
break;
}
/* Insert the prefix */
messages->textCursor().insertHtml( buf /* + "</i>" */ );
/* Insert the message */
messages->textCursor().insertHtml( msg->text );
/* Pass the new message thru the filter */
QTextBlock b = messages->document()->lastBlock();
b.setVisible( matchFilter( b.text() ) );
/* Tell the QTextDocument to recompute the size of the given area */
messages->document()->markContentsDirty( b.position(), b.length() );
if ( b_autoscroll ) messages->ensureCursorVisible();
}