本文整理汇总了C++中cursorPosition函数的典型用法代码示例。如果您正苦于以下问题:C++ cursorPosition函数的具体用法?C++ cursorPosition怎么用?C++ cursorPosition使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cursorPosition函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: charToDelete
void DigraphLineEdit::keyPressEvent( QKeyEvent* event ) {
if( digraphEnabled ) {
// We consider only printable keys. Control keys are processed normally.
// I'm not sure if this test covers all the cases though.
if( event->count() > 0 ) {
if( event->key() == Qt::Key_Backspace ) {
if( cursorPosition() > 0 ) {
if( buffer.isNull() ) {
QString charToDelete( text().mid( cursorPosition() - 1, 1 ) );
buffer = charToDelete;
}
else
buffer = QString::null;
}
}
else {
// Shift key is required to input some digraphs so it's a special case.
if( !buffer.isNull() && event->key() != Qt::Key_Shift ) {
buffer += event->text();
const QString newChar( Util::getDigraph( buffer ) );
if( newChar == QString::null )
buffer = QString::null;
else {
QKeyEvent* digraphEvent = new QKeyEvent( QEvent::KeyPress, 0, Qt::NoModifier, newChar, event->isAutoRepeat(), 0 );
QLineEdit::keyPressEvent( digraphEvent );
buffer = QString::null;
return;
}
}
}
}
}
QLineEdit::keyPressEvent( event );
}
开发者ID:FBergeron,项目名称:tomotko-fremantle,代码行数:34,代码来源:DigraphLineEdit.cpp
示例2: dialog
void lcl_OnyxLineEdit::keyPressEvent(QKeyEvent * ke)
{
if (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return)
{
NumberDialog dialog(0, name);
if (dialog.popup(text().toInt(), maxval) == QDialog::Accepted) {
int val = dialog.value();
QString s_val;
s_val = QString("%1").arg(val);
setText(s_val);
onyx::screen::instance().updateWidget(0, onyx::screen::ScreenProxy::GU);
emit valueChanged(this);
}
}
if ((ke->key() == Qt::Key_Left && cursorPosition() <= 0) ||
(ke->key() == Qt::Key_Right && cursorPosition() >= text().size()))
{
out_of_range_ = true;
}
QLineEdit::keyPressEvent(ke);
ke->accept();
update();
onyx::screen::watcher().enqueue(this, onyx::screen::ScreenProxy::DW, onyx::screen::ScreenCommand::WAIT_NONE);
}
开发者ID:MEHDIDZ16,项目名称:boox-opensource,代码行数:26,代码来源:line_edit.cpp
示例3: cursorRect
/** TagButton instances are converted with whitespaces in the LineEdit in order to move them. */
void TagLineEdit::insertSpaces()
{
TagButton *t = qobject_cast<TagButton*>(sender());
int cx = cursorRect().x();
t->setPosition(cursorPosition());
int numberOfSpace = 2;
this->setText(this->text().insert(cursorPosition(), " "));
cursorForward(false, 2);
while (t->frameGeometry().contains(cursorRect().center())) {
this->setText(this->text().insert(cursorPosition(), " "));
cursorForward(false);
numberOfSpace++;
}
t->setMinimumWidth(numberOfSpace * fontMetrics().width(" ") - 5);
t->setSpaceCount(numberOfSpace);
t->disconnect();
for (TagButton *tag : _tags) {
//qDebug() << Q_FUNC_INFO << "trying to move tag";
if (t != tag && tag->frameGeometry().x() > cx) {
//qDebug() << Q_FUNC_INFO << "moving tag" << tag->text();
tag->move(tag->x() + fontMetrics().width(" ") * numberOfSpace, 0);
}
}
}
开发者ID:percevall,项目名称:Miam-Player,代码行数:28,代码来源:taglineedit.cpp
示例4: cursorPosition
void GuidLineEdit::keyPressEvent(QKeyEvent * event)
{
if (event == QKeySequence::Delete || event->key() == Qt::Key_Backspace)
{
int pos = cursorPosition();
if (event->key() == Qt::Key_Backspace && pos > 0) {
cursorBackward(false);
pos = cursorPosition();
}
QString txt = text();
QString selected = selectedText();
if (!selected.isEmpty()) {
pos = QLineEdit::selectionStart();
for (int i = pos; i < pos + selected.count(); i++)
if (txt[i] != QChar('-'))
txt[i] = QChar('.');
}
else
txt[pos] = QChar('.');
setCursorPosition(0);
insert(txt);
setCursorPosition(pos);
return;
}
// Call original event handler
QLineEdit::keyPressEvent(event);
}
开发者ID:Fricsay,项目名称:UEFITool,代码行数:32,代码来源:guidlineedit.cpp
示例5: selectedText
void StatusEdit::shortenUrl()
{
if( hasSelectedText() ) {
selectedUrl = selectedText();
emit shortenUrl( selectedUrl );
} else {
QRegExp rx( "((ftp|http|https)://(\\w+:{0,1}\\w*@)?([^ ]+)(:[0-9]+)?(/|/([\\w#!:.?+=&%@!-/]))?)", Qt::CaseInsensitive );
int position = rx.indexIn( text() );
QString url = rx.capturedTexts().at( 1 );
if( cursorPosition() >= position && cursorPosition() <= url.length() + position ) {
selectedUrl = url;
emit shortenUrl( selectedUrl );
}
}
}
开发者ID:wiorka,项目名称:qtwitter,代码行数:16,代码来源:statusedit.cpp
示例6: setViewOK
void NumberEdit::texttChanged(const QString& text) {
QString in=text;
if (!suffix.isEmpty()) {
if (text.endsWith(suffix)) {
in=in.remove(text.size()-suffix.size(), suffix.size());
}
}
double d=extractVal(text);
setViewOK();
if ((checkMax) && (d>max)) {
d=max;
setViewError();
}//setValue(d);}
if ((checkMin) && (d<min)) {
d=min;
setViewError();
}//setValue(d); }
//std::cout<<d<<std::endl;
//QMessageBox::information(this, "", QString("value is %1").arg(d));
else emit valueChanged(d);
if ((!suffix.isEmpty()) && (!text.contains(suffix))) {
int cp=cursorPosition();
setText(text+suffix);
setCursorPosition(cp);
}
}
开发者ID:jkriege2,项目名称:LitSoz3,代码行数:27,代码来源:numberedit.cpp
示例7: Q_Q
void ByteArrayColumnViewPrivate::placeCursor( const QPoint& point )
{
Q_Q( ByteArrayColumnView );
// switch active column if needed
if( mCharColumn->isVisible() && point.x() >= mCharColumn->x() )
{
mActiveColumn = mCharColumn;
mInactiveColumn = mValueColumn;
}
else
{
mActiveColumn = mValueColumn;
mInactiveColumn = mCharColumn;
}
adaptController();
// get coord of click and whether this click was closer to the end of the pos
const int linePosition = mActiveColumn->magneticLinePositionOfX( point.x() );
const int lineIndex = q->lineAt( point.y() );
const Coord coord( linePosition, lineIndex );
mTableCursor->gotoCCoord( coord );
emit q->cursorPositionChanged( cursorPosition() );
}
开发者ID:ShermanHuang,项目名称:kdesdk,代码行数:25,代码来源:bytearraycolumnview_p.cpp
示例8: loadHistory
void QLineEditEx::keyPressEvent(QKeyEvent *e)
{
if(e->key() == Qt::Key_Up)
{
loadHistory(true,m_History,m_Index);
return;
}
else if (e->key() == Qt::Key_Down)
{
loadHistory(false,m_History,m_Index);
return;
}
else if(e->key() == Qt::Key_Left)
{
if(m_TabIndex != -1)
{
suggest(false);
return;
}
}
else if(e->key() == Qt::Key_Right)
{
if(cursorPosition() == text().length() || m_TabIndex != -1)
{
suggest(true);
return;
}
}
else
{
m_TabBase.clear();
m_TabIndex = -1;
}
QLineEdit::keyPressEvent(e);
}
开发者ID:0vermind,项目名称:NeoLoader,代码行数:35,代码来源:LineEditEx.cpp
示例9: cursorPosition
void KonqCombo::saveState()
{
m_cursorPos = cursorPosition();
m_currentText = currentText();
m_selectedText = lineEdit()->selectedText();
m_currentIndex = currentIndex();
}
开发者ID:theunbelievablerepo,项目名称:dolphin2.1,代码行数:7,代码来源:konqcombo.cpp
示例10: cursorPosition
void KTextBox::fitText()
{
int startindex, endindex, countindex, testlength, line, column;
// Map the text to the width of the widget
cursorPosition( &line, &column );
countindex =-1;
QString testText = text().simplifyWhiteSpace() + " ";
startindex = 0;
testlength = testText.length();
countindex = testText.find(" ", 0);
while ((endindex = testText.find(" ", countindex+1)) > -1) {
QString middle;
int len;
len = endindex - startindex;
middle = testText.mid( startindex, len );
if (textWidth( &middle ) > width()) {
testText.replace( countindex, 1, "\n" );
startindex = countindex;
}
countindex = endindex;
}
setText( testText.stripWhiteSpace() );
setCursorPosition( line, column );
}
开发者ID:kthxbyte,项目名称:KDE1-Linaro,代码行数:28,代码来源:eventwidget.cpp
示例11: clear
void MgCommandLine::keyPressEvent(QKeyEvent * e)
{
if(e->key() == Qt::Key_Escape )
clear();
else if((e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return ) && m_scriptEngine && m_completer->popup()->isVisible())
{
insertText(m_completer->popup()->currentIndex().data().toString());
m_completer->popup()->hide();
}
else if((e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return ) && m_scriptEngine)
{
m_scriptEngine->execCommand(text());
clear();
}
else if(e->key() == Qt::Key_Space && e->modifiers().testFlag(Qt::ControlModifier))
{
if(!m_completer->popup()->isVisible())
{
MgCommandCompleter completer(m_scriptEngine);
MgCommandCompleter::CompletionResult result = completer.completionOf(text(),cursorPosition());
m_completer->setCompletionPrefix("");
m_prefix = result.prefix;
m_completionModel->setStringList(result.completion);
m_completer->complete();
}
else
{
m_completer->popup()->hide();
}
}
else
QLineEdit::keyPressEvent(e);
}
开发者ID:kaabimg,项目名称:MgLibrary,代码行数:35,代码来源:mgcommandline.cpp
示例12: cursorPosition
void QcrLineEdit::doSetValue(QString val)
{
//keep cursor pos, so the cursor doesn't always jump to the end:
int oldCursorPos = cursorPosition();
setText(val);
this->setCursorPosition(oldCursorPos);
}
开发者ID:scgmlz,项目名称:Steca2,代码行数:7,代码来源:controls.cpp
示例13: beginOfWord
void LineEditHistory::complete()
{
QString para = this->text();
int wordStart = beginOfWord( false );
while (wordStart > 0 && para[wordStart - 1].isLetterOrNumber())
--wordStart;
wordPrefix = para.mid(wordStart, cursorPosition() - wordStart);
// if (wordPrefix.isEmpty())
// return;
QStringList list = searchSymbols;
QMap<QString, QString> map;
QStringList::Iterator it = list.begin();
while (it != list.end()) {
if ((*it).startsWith(wordPrefix) && (*it).length() > wordPrefix.length())
map[(*it).toLower()] = *it;
++it;
}
if (map.count() == 1) {
insert((*map.begin()).mid(wordPrefix.length()));
} else if (map.count() > 1) {
if (!listBox)
createListBox();
listBox->clear();
listBox->addItems( map.values() );
QPoint point = textCursorPoint();
listBox->move(point);
listBox->show();
listBox->raise();
listBox->activateWindow();
}
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:34,代码来源:lineedithistory.cpp
示例14: setToolTip
void BaseValidatingLineEdit::slotChanged(const QString &t)
{
m_bd->m_errorMessage.clear();
// Are we displaying the initial text?
const bool isDisplayingInitialText = !m_bd->m_initialText.isEmpty() && t == m_bd->m_initialText;
const State newState = isDisplayingInitialText ?
DisplayingInitialText :
(validate(t, &m_bd->m_errorMessage) ? Valid : Invalid);
setToolTip(m_bd->m_errorMessage);
if (debug)
qDebug() << Q_FUNC_INFO << t << "State" << m_bd->m_state << "->" << newState << m_bd->m_errorMessage;
// Changed..figure out if valid changed. DisplayingInitialText is not valid,
// but should not show error color. Also trigger on the first change.
if (newState != m_bd->m_state || m_bd->m_firstChange) {
const bool validHasChanged = (m_bd->m_state == Valid) != (newState == Valid);
m_bd->m_state = newState;
m_bd->m_firstChange = false;
setTextColor(this, newState == Invalid ? m_bd->m_errorTextColor : m_bd->m_okTextColor);
if (validHasChanged) {
emit validChanged(newState == Valid);
emit validChanged();
}
}
bool block = blockSignals(true);
const QString fixedString = fixInputString(t);
if (t != fixedString) {
const int cursorPos = cursorPosition();
setText(fixedString);
setCursorPosition(qMin(cursorPos, fixedString.length()));
}
blockSignals(block);
}
开发者ID:Daylie,项目名称:Totem,代码行数:32,代码来源:basevalidatinglineedit.cpp
示例15: textArea
void BookTextView::replaceCurrentPositionInStack() {
const ZLTextWordCursor &cursor = textArea().startCursor();
if (!cursor.isNull()) {
myPositionStack[myCurrentPointInStack] = cursorPosition(cursor);
myStackChanged = true;
}
}
开发者ID:euroelessar,项目名称:FBReader,代码行数:7,代码来源:BookTextView.cpp
示例16: cursorPosition
void
line_edit_autocomplete::show_completions()
{
if (!m_completer_enabled)
return;
QString prefix; // substring on which the completion is to be based
int pos = cursorPosition();
int start = get_prefix_pos(text(), pos);
if (start>=0) {
prefix=text().mid(start, pos-start);
}
if (prefix.isEmpty()) {
// nothing to complete
if (popup->isVisible()) {
popup->clear();
popup->hide();
}
}
else {
QList<QString> completions = get_completions(prefix);
redisplay_popup(completions);
}
}
开发者ID:manitou-mail,项目名称:manitou-mail-ui,代码行数:26,代码来源:line_edit_autocomplete.cpp
示例17: cursorPosition
void PropertyLineEdit::insertText(const QString &text) {
// position cursor after new text and grab focus
const int oldCursorPosition = cursorPosition ();
insert(text);
setCursorPosition (oldCursorPosition + text.length());
setFocus(Qt::OtherFocusReason);
}
开发者ID:RobinWuDev,项目名称:Qt,代码行数:7,代码来源:propertylineedit.cpp
示例18: cursorPosition
QPair<int, int> TagWidget::getCursorTagPosition()
{
int i = 0, start = 0, end = 0;
/* Parse string near cursor */
i = cursorPosition();
while (--i > 0) {
if (text().at(i) == ',') {
if (i > 0 && text().at(i - 1) != '\\') {
i++;
break;
}
}
}
start = i;
while (++i < text().length()) {
if (text().at(i) == ',') {
if (i > 0 && text().at(i - 1) != '\\')
break;
}
}
end = i;
if (start < 0 || end < 0) {
start = 0;
end = 0;
}
return qMakePair(start, end);
}
开发者ID:Farzana89,项目名称:subsurface,代码行数:27,代码来源:tagwidget.cpp
示例19: cursorPosition
void
SpinBox::setValue_internal(double d,
bool reformat)
{
if ( ( d == text().toDouble() ) && !reformat && _imp->valueInitialized ) {
// the value is already OK
return;
}
int pos = cursorPosition();
QString str;
switch (_imp->type) {
case eSpinBoxTypeDouble: {
str.setNum(d, 'f', _imp->decimals);
double toDouble = str.toDouble();
if (d != toDouble) {
str.setNum(d, 'g', 8);
}
break;
}
case eSpinBoxTypeInt:
str.setNum( (int)d );
break;
}
assert( !str.isEmpty() );
///Remove trailing 0s by hand...
int decimalPtPos = str.indexOf( QLatin1Char('.') );
if (decimalPtPos != -1) {
int i = str.size() - 1;
while ( i > decimalPtPos && str.at(i) == QLatin1Char('0') ) {
--i;
}
///let 1 trailing 0
if (i < str.size() - 1) {
++i;
}
str = str.left(i + 1);
}
// The following removes leading zeroes, but this is not necessary
/*
int i = 0;
bool skipFirst = false;
if (str.at(0) == '-') {
skipFirst = true;
++i;
}
while (i < str.size() && i == '0') {
++i;
}
if (i > int(skipFirst)) {
str = str.remove(int(skipFirst), i - int(skipFirst));
}
*/
_imp->valueWhenEnteringFocus = str;
setText(str, pos);
_imp->valueInitialized = true;
}
开发者ID:MrKepzie,项目名称:Natron,代码行数:59,代码来源:SpinBox.cpp
示例20: cursorPosition
QChar WizTitleEdit::charBeforeCursor()
{
int i = cursorPosition() - 1;
if (i >= 0)
return text().at(i);
return QChar();
}
开发者ID:WizTeam,项目名称:WizQTClient,代码行数:8,代码来源:WizTitleEdit.cpp
注:本文中的cursorPosition函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论