本文整理汇总了C++中QTextEdit::horizontalScrollBar方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextEdit::horizontalScrollBar方法的具体用法?C++ QTextEdit::horizontalScrollBar怎么用?C++ QTextEdit::horizontalScrollBar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextEdit
的用法示例。
在下文中一共展示了QTextEdit::horizontalScrollBar方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doHighlightText
void SourceViewer::doHighlightText(const QString &text, bool caseSensitive)
{
qDebug() << "doHighlightText : text=" << text;
workingHighlightText_ = true;
do
{
QTextEdit *logTextEdit = getCurrentSourceEdit();
if(logTextEdit == NULL)
break;
int orgValueVert = logTextEdit->verticalScrollBar()->value();
int orgValueHor = logTextEdit->horizontalScrollBar()->value();
QTextCursor orgCursor = logTextEdit->textCursor();
QTextDocument::FindFlags flags = 0x0;
if(caseSensitive)
flags |= QTextDocument::FindCaseSensitively;
QList<QTextEdit::ExtraSelection> extraSelections;
logTextEdit->moveCursor(QTextCursor::Start);
QColor fgColor = QColor("white");
QColor bgColor = QColor("#C32438");
while(logTextEdit->find(text, flags))
{
QTextEdit::ExtraSelection extra;
extra.format.setForeground(fgColor);
extra.format.setBackground(bgColor);
extra.cursor = logTextEdit->textCursor();
extraSelections.append(extra);
}
logTextEdit->setExtraSelections(extraSelections);
logTextEdit->setTextCursor(orgCursor);
logTextEdit->verticalScrollBar()->setValue(orgValueVert);
logTextEdit->horizontalScrollBar()->setValue(orgValueHor);
} while(false);
workingHighlightText_ = false;
}
示例2: 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!");
}
示例3: onClickedSearchPrev
void SourceViewer::onClickedSearchPrev()
{
QTextEdit *logTextEdit = getCurrentSourceEdit();
if(logTextEdit != NULL)
{
QTextDocument::FindFlags flags = QTextDocument::FindBackward;
if(ui.caseSensitiveCheck->isChecked())
flags |= QTextDocument::FindCaseSensitively;
bool find = logTextEdit->find(ui.searchText->text(), flags);
if(find == false)
{
logTextEdit->moveCursor(QTextCursor::End);
logTextEdit->horizontalScrollBar()->setValue(0);
logTextEdit->find(ui.searchText->text(), flags);
}
}
}
示例4: main
int main(int argc, char **argv)
{
Vals vals;
/* the application */
QApplication app(argc, argv);
app.setApplicationName(APP_NAME);
app.setWindowIcon(QIcon(":/icon"));
Window window;
/* translations */
QTranslator qtr;
if (qtr.load("qt_" + QLocale::system().name(), QTR_PATH))
app.installTranslator(&qtr);
QTranslator htr;
if (htr.load("H4KvT_" + QLocale::system().name(), ":/"))
app.installTranslator(&htr);
/* display information */
QTextEdit *text = new QTextEdit;
text->setReadOnly(true);
text->setLineWrapMode(QTextEdit::NoWrap);
text->setToolTip(Window::tr("Drop any file for hashing"));
QObject::connect(&window, &Window::idle, text, &QWidget::setEnabled);
/* compare hash */
QLineEdit *test = new QLineEdit;
HexVal hexval;
test->setValidator(&hexval);
test->installEventFilter(&window);
test->setToolTip(Window::tr("Compare hashes"));
QObject::connect(test, &QLineEdit::textChanged,
[&](const QString &newValue) { if (vals.name != "") {
std::string hashVal = newValue.toStdString();
std::transform(hashVal.begin(), hashVal.end(), hashVal.begin(), ::tolower);
std::stringstream html;
if (hashVal != "")
html << "<style>.h" << hashVal << "{color:green}</style>";
html << "<div style='margin-bottom:2; font-size:27px'><i><b>" << vals.name << "</b></i></div>";
html << "<div style='margin-bottom:7; margin-left:23; font-size:13px'>" << vals.path << "</div>";
if (!ALL(vals,"")) {
html << "<div style='font-size:13px'><table>";
if (vals.md5 != "")
html << "<tr><td>md5: </td><td class='h" << vals.md5 << "'>" << vals.md5 << "</td</tr>";
if (vals.sha1 != "")
html << "<tr><td>sha1: </td><td class='h" << vals.sha1 << "'>" << vals.sha1 << "</td</tr>";
if (vals.sha224 != "")
html << "<tr><td>sha224: </td><td class='h" << vals.sha224 << "'>" << vals.sha224 << "</td</tr>";
if (vals.sha256 != "")
html << "<tr><td>sha256: </td><td class='h" << vals.sha256 << "'>" << vals.sha256 << "</td</tr>";
if (vals.sha384 != "")
html << "<tr><td>sha384: </td><td class='h" << vals.sha384 << "'>" << vals.sha384 << "</td</tr>";
if (vals.sha512 != "")
html << "<tr><td>sha512: </td><td class='h" << vals.sha512 << "'>" << vals.sha512 << "</td</tr>";
html << "</table></div>";
}
int horizontal = text->horizontalScrollBar()->value();
int vertical = text->verticalScrollBar()->value();
text->setHtml(QString::fromStdString(html.str()));
text->horizontalScrollBar()->setValue(horizontal);
text->verticalScrollBar()->setValue(vertical);
test->setStyleSheet(ANY(vals,hashVal) ? "color:green" : "");
}});
/* error messages */
QLabel *error = new QLabel;
error->setStyleSheet("color:red");
/* test or error */
QStackedWidget *stack = new QStackedWidget;
delete stack->layout();
stack->setLayout(new Stack);
stack->addWidget(error);
stack->addWidget(test);
stack->setCurrentIndex(1);
/* toggle test or error */
QPushButton *hash = new QPushButton(QIcon(":/icon"), "");
hash->setCheckable(true);
hash->setChecked(true);
hash->setToolTip(Window::tr("Compare hashes"));
QObject::connect(hash, &QPushButton::toggled, stack, &QStackedWidget::setCurrentIndex);
/* store method */
QSettings settings("H4KvT", "H4KvT");
/* more methods */
bool more;
try {
settings.setValue("MoreHashingMethods", more = moreOrLess());
} catch (...) {
more = settings.value("MoreHashingMethods", false).toBool();
}
/* hashing method */
QComboBox *meth = new QComboBox;
meth->addItem("md5");
meth->addItem("sha1");
//.........这里部分代码省略.........