本文整理汇总了C++中QTextEdit::cursorRect方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextEdit::cursorRect方法的具体用法?C++ QTextEdit::cursorRect怎么用?C++ QTextEdit::cursorRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextEdit
的用法示例。
在下文中一共展示了QTextEdit::cursorRect方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: alignment
/*
* Copyright 2000-2015 Rochus Keller <mailto:[email protected]>
*
* This file is part of the CARA (Computer Aided Resonance Assignment,
* see <http://cara.nmr.ch/>) NMR Application Framework (NAF) library.
*
* The following is the license that applies to this copy of the
* library. For a license to use the library under conditions
* other than those described here, please email to [email protected]
*
* GNU General Public License Usage
* This file may be used under the terms of the GNU General Public
* License (GPL) versions 2.0 or 3.0 as published by the Free Software
* Foundation and appearing in the file LICENSE.GPL included in
* the packaging of this file. Please review the following information
* to ensure GNU General Public Licensing requirements will be met:
* http://www.fsf.org/licensing/licenses/info/GPLv2.html and
* http://www.gnu.org/copyleft/gpl.html.
*/
#include <QTextEdit>
#include "QtlTextEdit.h"
#include "Enums.h"
#include <QString>
#include <QMenu>
#include <QList>
#include <QPoint>
#include <QUrl>
#include <QTextCursor>
#include <QTextCharFormat>
#include <QInputContext>
#include <Script/ObjectInstaller.h>
#include <Script/ValueInstaller.h>
#include "Variant.h"
using namespace Qtl;
using namespace Lua;
int TextEdit::alignment(lua_State * L) // const : Qt::Alignment
{
QTextEdit* obj = ObjectHelper<QTextEdit>::check( L, 1);
Lua::Util::push( L, obj->alignment() );
return 1;
}
int TextEdit::anchorAt(lua_State * L) // ( const QPoint & pos ) const : QString
{
QTextEdit* obj = ObjectHelper<QTextEdit>::check( L, 1);
QPointF* p = ValueInstaller2<QPointF>::check( L, 2 );
lua_pushstring(L, obj->anchorAt( p->toPoint() ).toLatin1() );
return 1;
}
int TextEdit::canPaste(lua_State * L) // const : bool
{
QTextEdit* obj = ObjectHelper<QTextEdit>::check( L, 1);
Lua::Util::push( L, obj->canPaste() );
return 1;
}
int TextEdit::createStandardContextMenu(lua_State * L) // const : QMenu*
{
QTextEdit* obj = ObjectHelper<QTextEdit>::check( L, 1);
ObjectPeer::pushPeer( L, obj->createStandardContextMenu(), true);
return 1;
}
int TextEdit::currentCharFormat(lua_State * L) // const : QTextCharFormat
{
QTextEdit* obj = ObjectHelper<QTextEdit>::check( L, 1);
QTextCharFormat* res = ValueInstaller2<QTextCharFormat>::create( L );
*res = obj->currentCharFormat();
return 1;
}
int TextEdit::currentFont(lua_State * L) // const : QFont
{
QTextEdit* obj = ObjectHelper<QTextEdit>::check( L, 1);
QFont* res = ValueInstaller2<QFont>::create( L );
*res = obj->currentFont();
return 1;
}/*
int TextEdit::cursorForPosition(lua_State * L) // ( const QPoint & pos ) const : QTextCursor
{
QTextEdit* obj = ObjectHelper<QTextEdit>::check( L, 1);
QPoint* p = ValueInstaller2<QPoint>::check( L, 2 );
QTextCursor* res = ValueInstaller2<QTextCursor>::create( L );
*res = obj->cursorForPosition( p->toPoint() );
return 1;
}*/
int TextEdit::cursorRect(lua_State * L) // ( const QTextCursor & cursor ) const : QRect
// const : QRect
{
QTextEdit* obj = ObjectHelper<QTextEdit>::check( L, 1 );
QRectF* res = ValueInstaller2<QRectF>::create( L );
if(QTextCursor* cursor = ValueInstaller2<QTextCursor>::check( L, 2 ))
{
*res = obj->cursorRect( *cursor );
}
else
{
*res = obj->cursorRect();
}
return 1;
}
示例2: cursorRect
QRect QTextEditProto::cursorRect() const
{
QTextEdit *item = qscriptvalue_cast<QTextEdit*>(thisObject());
if (item)
return item->cursorRect();
return QRect();
}
示例3: scrollToSubstring
void QAccessibleTextEdit::scrollToSubstring(int startIndex, int endIndex)
{
QTextEdit *edit = textEdit();
QTextCursor cursor = textCursor();
cursor.setPosition(startIndex);
QRect r = edit->cursorRect(cursor);
cursor.setPosition(endIndex);
r.setBottomRight(edit->cursorRect(cursor).bottomRight());
r.moveTo(r.x() + edit->horizontalScrollBar()->value(),
r.y() + edit->verticalScrollBar()->value());
// E V I L, but ensureVisible is not public
if (!QMetaObject::invokeMethod(edit, "_q_ensureVisible", Q_ARG(QRectF, r)))
qWarning("AccessibleTextEdit::scrollToSubstring failed!");
}
示例4:
QMap<int, QList<QRectF>> TextDocumentAdapter::GetTextPositions (const QString& text, Qt::CaseSensitivity cs)
{
const auto& pageSize = Doc_->pageSize ();
const auto pageHeight = pageSize.height ();
QTextEdit hackyEdit;
hackyEdit.setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
hackyEdit.setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
hackyEdit.setFixedSize (Doc_->pageSize ().toSize ());
hackyEdit.setDocument (Doc_.get ());
Doc_->setPageSize (pageSize);
const auto tdFlags = cs == Qt::CaseSensitive ?
QTextDocument::FindCaseSensitively :
QTextDocument::FindFlags ();
QMap<int, QList<QRectF>> result;
auto cursor = Doc_->find (text, 0, tdFlags);
while (!cursor.isNull ())
{
auto endRect = hackyEdit.cursorRect (cursor);
auto startCursor = cursor;
startCursor.setPosition (cursor.selectionStart ());
auto rect = hackyEdit.cursorRect (startCursor);
const int pageNum = rect.y () / pageHeight;
rect.moveTop (rect.y () - pageHeight * pageNum);
endRect.moveTop (endRect.y () - pageHeight * pageNum);
if (rect.y () != endRect.y ())
{
rect.setWidth (pageSize.width () - rect.x ());
endRect.setX (0);
}
auto bounding = rect | endRect;
result [pageNum] << bounding;
cursor = Doc_->find (text, cursor, tdFlags);
}
return result;
}
示例5: eventFilter
bool QWordCompleter::eventFilter(QObject *o, QEvent *e)
{
if(widget()->inherits("QTextEdit") && e->type() == QEvent::KeyPress){
QKeyEvent* ke = static_cast<QKeyEvent*>(e);
switch (ke->key()) {
case Qt::Key_Space:
if(ke->modifiers().testFlag(Qt::ControlModifier)){
QTextEdit* textEdit = qobject_cast<QTextEdit*>(widget());
QTextCursor textCursor = textEdit->textCursor();
textCursor.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor);
if(textCursor.selectedText().length() >= minCompletionPrefixLength){
setCompletionPrefix(textCursor.selectedText());
QRect rect = QRect(textEdit->cursorRect().bottomLeft(), QSize(100, 5));
complete(rect);
}
return true;
}
break;
case Qt::Key_Enter:
case Qt::Key_Return:
case Qt::Key_Tab:
if(popup()->isVisible()){
popup()->hide();
if(popup()->currentIndex().isValid()){
emit activated(popup()->currentIndex());
emit activated(popup()->currentIndex().data(completionRole()).toString());
}
return true;
}
default:
break;
}
}
return QCompleter::eventFilter(o, e);
}