本文整理汇总了C++中QTextFragment::contains方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextFragment::contains方法的具体用法?C++ QTextFragment::contains怎么用?C++ QTextFragment::contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextFragment
的用法示例。
在下文中一共展示了QTextFragment::contains方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getFragmentUnderMouse
QTextFragment ChatView::getFragmentUnderMouse(const QPoint &pos) const
{
QTextCursor cursor(cursorForPosition(pos));
QTextBlock block(cursor.block());
QTextBlock::iterator it;
for (it = block.begin(); !(it.atEnd()); ++it) {
QTextFragment frag = it.fragment();
if (frag.contains(cursor.position()))
return frag;
}
return QTextFragment();
}
示例2: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTextEdit *editor = new QTextEdit;
QTextDocument *document = new QTextDocument(editor);
QTextCursor cursor(document);
QTextImageFormat imageFormat;
imageFormat.setName(":/images/advert.png");
cursor.insertImage(imageFormat);
QTextBlock block = cursor.block();
QTextFragment fragment;
QTextBlock::iterator it;
for (it = block.begin(); !(it.atEnd()); ++it) {
fragment = it.fragment();
if (fragment.contains(cursor.position()))
break;
}
//! [0]
if (fragment.isValid()) {
QTextImageFormat newImageFormat = fragment.charFormat().toImageFormat();
if (newImageFormat.isValid()) {
newImageFormat.setName(":/images/newimage.png");
QTextCursor helper = cursor;
helper.setPosition(fragment.position());
helper.setPosition(fragment.position() + fragment.length(),
QTextCursor::KeepAnchor);
helper.setCharFormat(newImageFormat);
//! [0] //! [1]
}
//! [1] //! [2]
}
//! [2]
cursor.insertBlock();
cursor.insertText("Code less. Create more.");
editor->setDocument(document);
editor->setWindowTitle(tr("Text Document Image Format"));
editor->resize(320, 480);
editor->show();
return app.exec();
}