本文整理汇总了C++中QTextEdit::ensureCursorVisible方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextEdit::ensureCursorVisible方法的具体用法?C++ QTextEdit::ensureCursorVisible怎么用?C++ QTextEdit::ensureCursorVisible使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextEdit
的用法示例。
在下文中一共展示了QTextEdit::ensureCursorVisible方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: editMenuActivated
void editMenuActivated(QAction *action)
{
QWidget* w = qApp->focusWidget();
QTextEdit* te = qobject_cast<QTextEdit*>(w);
QLineEdit* le = qobject_cast<QLineEdit*>(w);
if (action == selectAction) {
highlighting = this;
return;
}
highlighting = 0;
if (action == copyAction) {
if (te) {
if (te->hasEditFocus()) {
te->copy();
} else {
QTextCursor c = te->textCursor();
te->selectAll();
te->copy();
te->setTextCursor(c); // reset selection
}
} else if (le) {
if (le->hasEditFocus()) {
le->copy();
} else {
qApp->clipboard()->setText(le->text());
}
}
} else if (action == pasteAction) {
// assumes clipboard is not empty if 'Paste' is able to be
// activated, otherwise the line/textedit might be cleared
// without pasting anything back into it
if (te) {
if (!te->hasEditFocus())
te->clear();
te->paste();
if (!te->hasEditFocus()) {
te->moveCursor(QTextCursor::Start);
te->ensureCursorVisible();
}
} else if (le) {
if (!le->hasEditFocus())
le->clear();
le->paste();
if (!le->hasEditFocus())
le->home(false);
}
}
}
示例2: ensureCursorVisible
int TextEdit::ensureCursorVisible(lua_State * L)
{
QTextEdit* obj = ObjectHelper<QTextEdit>::check( L, 1);
obj->ensureCursorVisible();
return 0;
}
示例3: if
//.........这里部分代码省略.........
if (messagecount == 1)
lineEdit->setText(tr(messages[0]));
height = lineEdit->font().pointSize() + 4;
if (height < 0)
height = lineEdit->font().pixelSize() + 4;
if (height < 0)
height = lineEdit->heightForWidth(width) + 4;
lineEdit->setSizePolicy(QSizePolicy::MinimumExpanding,
QSizePolicy::Fixed);
lineEdit->setMinimumSize(QSize(width, height));
lineEdit->setGeometry(QRect(0, 0, width, height));
vboxLayout1->addWidget(lineEdit);
}
else {
QFont fixed("monospace");
fixed.setStyleHint(QFont::TypeWriter);
textEdit = new QTextEdit(this);
textEdit->setFont(fixed);
textEdit->setLineWrapMode(QTextEdit::FixedColumnWidth);
textEdit->setLineWrapColumnOrWidth(80);
textEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
if (nosliderflag)
textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
else if (usesliderflag)
textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
else
textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
for (int m = 0; m < messagecount; m++)
textEdit->append(tr(messages[m]));
if (inputflag)
textEdit->setReadOnly(false);
else {
textEdit->setLineWidth(1);
textEdit->setFrameStyle(noframeflag ? QFrame::NoFrame :
QFrame::Box | QFrame::Sunken);
textEdit->setReadOnly(true);
}
if (usesliderflag)
height = DEFAULT_EDIT_HEIGHT;
else {
height = textEdit->font().pointSize() + 4;
if (height < 0)
height = textEdit->font().pixelSize() + 4;
if (height < 0)
height = textEdit->heightForWidth(width) + 4;
height *= messagecount;
}
textEdit->setMinimumSize(QSize(width, height));
textEdit->setSizePolicy(QSizePolicy::MinimumExpanding,
QSizePolicy::MinimumExpanding);
textEdit->moveCursor(QTextCursor::Start);
textEdit->ensureCursorVisible();
vboxLayout1->addWidget(textEdit);
}
hboxLayout1 = new QHBoxLayout();
hboxLayout1->setSpacing(6);
hboxLayout1->setMargin(0);
spacerItem2 = new QSpacerItem(40, 20, QSizePolicy::Expanding,
QSizePolicy::Minimum);
hboxLayout1->addItem(spacerItem2);
for (int i = 0; i < buttoncount; i++) {
QueryButton *button = new QueryButton(printflag, this);
button->setMinimumSize(QSize(72, 32));
button->setDefault(buttons[i] == defaultbutton);
button->setQuery(this);
button->setText(tr(buttons[i]));
button->setStatus(statusi[i]);
if (inputflag && buttons[i] == defaultbutton) {
if (textEdit)
button->setEditor(textEdit);
else if (lineEdit) {
button->setEditor(lineEdit);
if (buttons[i] == defaultbutton)
connect(lineEdit, SIGNAL(returnPressed()),
button, SLOT(click()));
}
}
connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
hboxLayout1->addWidget(button);
}
vboxLayout1->addLayout(hboxLayout1);
hboxLayout->addLayout(vboxLayout1);
gridLayout->addLayout(hboxLayout, 0, 0, 1, 1);
gridLayout->setSizeConstraint(QLayout::SetFixedSize);
if (inputflag && messagecount <= 1)
resize(QSize(320, 83));
else
resize(QSize(320, 132));
if (timeout)
startTimer(timeout * 1000);
if (exclusiveflag)
setWindowModality(Qt::WindowModal);
}
示例4: ensureCursorVisible
void QTextEditProto::ensureCursorVisible()
{
QTextEdit *item = qscriptvalue_cast<QTextEdit*>(thisObject());
if (item)
item->ensureCursorVisible();
}
示例5: eventFilter
bool EmulApp::eventFilter(QObject *watched, QEvent *event)
{
int type = static_cast<int>(event->type());
if (type == QEvent::KeyPress) {
}
MainWindow *mw = dynamic_cast<MainWindow *>(watched);
if (mw) {
if (type == LogLineEventType) {
LogLineEvent *evt = dynamic_cast<LogLineEvent *>(event);
if (evt && mw->textEdit()) {
QTextEdit *te = mw->textEdit();
QColor origcolor = te->textColor();
te->setTextColor(evt->color);
te->append(evt->str);
// make sure the log textedit doesn't grow forever
// so prune old lines when a threshold is hit
nLinesInLog += evt->str.split("\n").size();
if (nLinesInLog > nLinesInLogMax) {
const int n2del = MAX(nLinesInLogMax/10, nLinesInLog-nLinesInLogMax);
QTextCursor cursor = te->textCursor();
cursor.movePosition(QTextCursor::Start);
for (int i = 0; i < n2del; ++i) {
cursor.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor);
}
cursor.removeSelectedText(); // deletes the lines, leaves a blank line
nLinesInLog -= n2del;
}
te->setTextColor(origcolor);
te->moveCursor(QTextCursor::End);
te->ensureCursorVisible();
return true;
} else {
return false;
}
} else if (type == StatusMsgEventType) {
StatusMsgEvent *evt = dynamic_cast<StatusMsgEvent *>(event);
if (evt && mw->statusBar()) {
mw->statusBar()->showMessage(evt->msg, evt->timeout);
return true;
} else {
return false;
}
}
}
if (watched == this) {
if (type == QuitEventType) {
quit();
return true;
}
if (type == SoundTrigEventType) {
SoundTrigEvent *evt = dynamic_cast<SoundTrigEvent *>(event);
if (evt) trigSound(evt->trig);
if (evt->listener) evt->listener->triggered(evt->trig);
return true;
}
if (type == SoundEventType) {
SoundEvent *evt = dynamic_cast<SoundEvent *>(event);
if (evt) gotSound(evt->id, evt->name, evt->loops);
if (evt->listener) evt->listener->gotSound(evt->id);
return true;
}
}
// otherwise do default action for event which probably means
// propagate it down
return QApplication::eventFilter(watched, event);
}