本文整理汇总了C++中QTextCursor::insertImage方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextCursor::insertImage方法的具体用法?C++ QTextCursor::insertImage怎么用?C++ QTextCursor::insertImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextCursor
的用法示例。
在下文中一共展示了QTextCursor::insertImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_button_smilely_clicked
void CommentDialog::on_button_smilely_clicked()
{
QSelectFaceWidget* selectFace = new QSelectFaceWidget(Global::emotionPathTemp, this);
selectFace->setStyleSheet("QLabel{color: #000000}QPushButton{background-color: transparent}");
QPoint GlobalPoint(this->ui.button_smilely->mapToGlobal(QPoint(0, 0)));//获取控件在窗体中的坐标
int y = GlobalPoint.y();
selectFace->popUp(GlobalPoint, this->ui.button_smilely->height()+10);
QObject::connect(selectFace, &QSelectFaceWidget::FaceSelected, [=](const QString &filename){
QString iconName = GetPicName(filename);
QTextDocument *document =this->ui.TextEdit_commentText->document();
QTextCursor cursor = this->ui.TextEdit_commentText->textCursor();
QFileInfo fiPic(filename);
if (fiPic.exists())
{
QImage image(filename);
image = image.scaled(30, 30, Qt::KeepAspectRatio, Qt::SmoothTransformation);
document->addResource(QTextDocument::ImageResource, QUrl(iconName), image);
cursor.insertImage(iconName);
}
this->ui.TextEdit_commentText->setFocus();
//this->ui.TextEdit_commentText->moveCursor(QTextCursor::NoMove);
});
};
示例2: addLink
void DocBlock::addLink(QUrl url)
{
myTextItem->setTextInteractionFlags(Qt::TextSelectableByKeyboard);
docType = Link;
path = url.toString();
QString str = path;
// add file icon
QTextCursor cursor = QTextCursor(myTextItem->document());
QFileInfo info(url.toLocalFile());
QFileIconProvider *provider = new QFileIconProvider();
QImage image(provider->icon(info).pixmap(16, 16).toImage());
cursor.document()->setPlainText(" ");
cursor.insertImage(image);
if (str.lastIndexOf("/") > -1)
str = str.right(str.size() - str.lastIndexOf("/") - 1);
QString html = "<a href=\""+path+"\">"+str+"</a>";
cursor.insertHtml(html);
if (arrow != 0) arrow->setColor(getHoverColor());
updateBlock(false);
}
示例3: parseBlock
void Format::parseBlock( QTextCursor &cursor, const QDomElement &element )
{
// dbg() << "Format::parseBlock()" << endl;
QDomNode n;
for( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
QDomElement e = n.toElement();
if ( e.tagName() == "fragment" ) {
QTextCharFormat format;
if ( e.hasAttribute( "link" ) ) {
format.setAnchor( true );
QString href = e.attribute( "link" );
format.setAnchorHref( href );
format.setFontUnderline( true );
if ( href.startsWith( "todoodle:" ) ) {
format = TextFormats::topicLinkCharFormat( href );
} else {
format = TextFormats::hyperLinkCharFormat( href );
}
}
if ( e.attribute( "bold" ) == "true" ) {
format.setFontWeight( QFont::Bold );
}
if ( e.attribute( "italic" ) == "true" ) {
format.setFontItalic( true );
}
int fontSize = 0;
if ( e.hasAttribute( "fontsize" ) ) {
fontSize = e.attribute( "fontsize" ).toInt();
} else {
fontSize = 10;
}
if ( fontSize > 0 ) format.setFontPointSize( fontSize );
QDomNode n2;
for( n2 = e.firstChild(); !n2.isNull(); n2 = n2.nextSibling() ) {
// dbg() << "TICK" << endl;
QDomText t = n2.toText();
if ( !t.isNull() ) {
// dbg() << "TEXT: '" << t.data() << "'" << endl;
cursor.insertText( t.data(), format );
// dbg() << "done" << endl;
} else {
QDomElement e2 = n2.toElement();
if ( !e2.isNull() ) {
if ( e2.tagName() == "todo" ) {
QTextImageFormat f;
if ( e2.attribute( "status" ) == "todo" ) {
f.setName( ":/images/todo.png" );
} else {
f.setName( ":/images/tododone.png" );
}
cursor.insertImage( f );
}
}
}
}
}
}
}
示例4: readCaml
void CamlDevWindow::readCaml()
{
QString stdOut = camlProcess->readAllStandardOutput();
stdOut = removeUnusedLineBreaks(stdOut,false);
if(drawTrees)
{
while(stdOut.indexOf("--LemonCamlCommand--") != -1)
{
int j = stdOut.indexOf("--LemonCamlCommand--"); //20
int p = stdOut.indexOf("--EndLemonCamlCommand--"); //23
if(p == -1)
{
appendOutput(tr("---LemonCaml error--- Unterminated command: not interpreted\n"), Qt::red);
stdOut = stdOut.mid(j + 20);
}
else
{
appendOutput(stdOut.left(j),this->palette().color(QPalette::WindowText));
QString cmd = stdOut.mid(j + 20, (p - j - 20));
QStringList cmdlist = parseBlockCommand(cmd);
processCommandList(&cmdlist);
stdOut = stdOut.mid(p + 23);
}
}
while(stdOut.indexOf("--LemonTree--") != -1) //TODO: change this!!!! never leave such an absolute type name here; ask the user, instead.
{
int j = stdOut.indexOf("--LemonTree--"); // 17
int p = stdOut.indexOf("--EndLemonTree--"); //20
if(p == -1)
{
appendOutput(tr("---LemonCaml error--- Unterminated tree: not drawn\n"), Qt::red);
stdOut = stdOut.mid(j + 17);
}
else
{
appendOutput(stdOut.left(j),this->palette().color(QPalette::WindowText));
QString arb = stdOut.mid(j + 13, (p - j - 13));
int k = arb.indexOf('(');
if(k != -1)
{
QString arbString = arb.mid(k);
treeParser* tp = new treeParser();
QImage* img = tp->parseTree(arbString);
QTextCursor cursor = outputZone->textCursor();
cursor.insertImage((*img), QString(this->graphCount));
outputZone->insertPlainText("\n");
this->graphCount++;
}
stdOut = stdOut.mid(p + 16);
}
}
}
if(stdOut != "") appendOutput(stdOut,this->palette().color(QPalette::WindowText));
}
示例5: addImageToDescription
void FormattedTextWidget::addImageToDescription()
{
QString filename = QFileDialog::getOpenFileName( this, tr( "Choose image" ), tr( "All Supported Files (*.png *.jpg *.jpeg)" ) );
QImage image( filename );
if( !image.isNull() ) {
QTextCursor cursor = d->m_description->textCursor();
cursor.insertImage( image, filename );
}
}
示例6: insertFromMimeData
//! [1]
void TextEdit::insertFromMimeData( const QMimeData *source )
{
if (source->hasImage())
{
QImage image = qvariant_cast<QImage>(source->imageData());
QTextCursor cursor = this->textCursor();
QTextDocument *document = this->document();
document->addResource(QTextDocument::ImageResource, QUrl("image"), image);
cursor.insertImage("image");
}
}
示例7: textCursor
void
BioWidget::insertWidget( QWidget* w )
{
w->installEventFilter( this );
m_widgetImageFormat.setObjectType( WidgetImageFormat );
m_widgetImageFormat.setProperty( WidgetData, QVariant::fromValue<QWidget*>( w ) );
m_widgetImageFormat.setName( w->objectName() );
QTextCursor cursor = textCursor();
cursor.insertImage( m_widgetImageFormat, QTextFrameFormat::FloatLeft );
setTextCursor( cursor );
}
示例8: peerCaptchaRequest
void messages_widget::peerCaptchaRequest(const libed2k::net_identifier& np, const QString& hash, const QPixmap& pm)
{
Q_UNUSED(hash);
std::vector<USER>::iterator it = findUser(np);
if ( it != users.end())
{
addSystemMessage(it->edit, tr("*** To avoid spam user is asking for captcha authentification. Please enter symbols on the picture below:\n"));
QTextCursor cursor = it->edit->textCursor();
cursor.insertImage(pm.toImage());
it->edit->append("\n");
}
}
示例9: insertEmoji
void FlatTextarea::insertEmoji(EmojiPtr emoji, QTextCursor c) {
c.removeSelectedText();
QPixmap img(App::emojiSingle(emoji, _st.font->height));
QString url = qsl("emoji://e.") + QString::number(emojiKey(emoji), 16);
document()->addResource(QTextDocument::ImageResource, QUrl(url), QVariant(img));
QTextImageFormat imageFormat;
imageFormat.setWidth(img.width() / cIntRetinaFactor());
imageFormat.setHeight(img.height() / cIntRetinaFactor());
imageFormat.setName(url);
imageFormat.setVerticalAlignment(QTextCharFormat::AlignBaseline);
c.insertImage(imageFormat);
}
示例10: addImage
void DocBlock::addImage(const QImage &image, QString imagePath)
{
myTextItem->setTextInteractionFlags(Qt::TextSelectableByKeyboard);
docType = Image;
QTextCursor cursor = QTextCursor(myTextItem->document());
cursor.document()->setPlainText("");
cursor.insertImage(image);
path = imagePath;
if (arrow != 0) arrow->setColor(getHoverColor());
updateBlock(false);
}
示例11: displayAttachments
void MailViewer::displayAttachments(const MessageHeader& msg)
{
#if 0 //code doesn't yet work
QTextDocument* textDocument = ui->message_content->document();
QImage image;
int i = 1;
foreach (const bts::bitchat::attachment& attachment, msg.attachments)
{
image.fromData(attachment.body.data());
QUrl url(QString("attachment_image_%1").arg(i++));
textDocument->addResource( QTextDocument::ImageResource, url, QVariant ( image ) );
QTextCursor cursor = ui->message_content->textCursor();
QTextImageFormat imageFormat;
imageFormat.setWidth( image.width() );
imageFormat.setHeight( image.height() );
imageFormat.setName( url.toString() );
cursor.insertImage(imageFormat);
}
#endif
}
示例12: imageOpen
void TextEdit::imageOpen()
{
QString fn = QFileDialog::getOpenFileName(this, tr("Open File..."),
QString(), tr("images (*.png *.bmp *.jpg *.jpeg);;All Files (*)"));
if (!fn.isEmpty()) {
QMimeData mimeData;
mimeData.setImageData(QImage(fn));
QTextCursor cursor = this->textEdit->textCursor();
QTextDocument *document = this->textEdit->document();
QString newfile, imageName;
do {
imageName = name + "/img_" + QTime::currentTime().toString("mmsszzz.") + fn.section(".",-1);
newfile = path + imageName;
} while(QFile::exists(newfile));
QFile::copy(fn, newfile);
document->addResource(QTextDocument::ImageResource, newfile, QImage(newfile));
cursor.insertImage(imageName);
listAddedImages<<newfile;
}
}
示例13: canInsertFromMimeData
def canInsertFromMimeData(source):
if source.hasImage:
return True
else:
return QTextEdit.canInsertFromMimeData(source)
//! [0]
//! [1]
void TextEdit::insertFromMimeData( const QMimeData *source )
{
if (source->hasImage())
{
QImage image = qvariant_cast<QImage>(source->imageData());
QTextCursor cursor = this->textCursor();
QTextDocument *document = this->document();
document->addResource(QTextDocument::ImageResource, QUrl("image"), image);
cursor.insertImage("image");
}
}
示例14: setFolded
void DocBlock::setFolded(bool fold)
{
if (fold == folded) return; //! do nothing
folded = fold;
if (fold)
{
backup = myTextItem->document()->clone();
if (docType == Image)
{
QTextCursor cursor = QTextCursor(myTextItem->document());
cursor.document()->setPlainText(" ");
cursor.insertImage(QImage(":/image.png"));
cursor.insertText(QFileInfo(path).fileName());
}
else
{
QString cue = myTextItem->toPlainText();
int index = cue.indexOf("\n");
cue.truncate(qMin(8, index));
cue.append(" ...");
myTextItem->setPlainText(cue);
myTextItem->setTextInteractionFlags(Qt::TextEditable | Qt::TextSelectableByKeyboard);
}
}
else
{
Q_ASSERT(backup != 0);
myTextItem->setDocument(backup);
if (!docType == Text)
myTextItem->setTextInteractionFlags(Qt::NoTextInteraction);
backup = 0;
}
updateBlock();
}
示例15: on_insertImage_clicked
void MainWindow::on_insertImage_clicked()
{
//get select image
QString fn = QFileDialog::getOpenFileName(this, tr("插入图像"),
QString(),
tr("Joint Photographic Experts Group (*.jpg *.jpeg);;") +
"Portable Network Graphics (*.png);;" +
"Windows Bitmap (*.bmp);;" +
"GIF (*.gif);;" +
"Portable Bitmap (*.pbm);;" +
"Portable Graymap (*.pgm);;" +
"Portable Pixmap (*.ppm);;" +
"X11 Bitmap (*.xbm);;" +
"X11 Pixmap (*.xpm);;" +
"Scalable Vector Graphics (*.svg);;" +
"All Files (*)");
if (fn.isEmpty())
return;
if (!(fn.endsWith(".jpg", Qt::CaseInsensitive)
|| fn.endsWith(".jpeg", Qt::CaseInsensitive)
|| fn.endsWith(".png", Qt::CaseInsensitive)
|| fn.endsWith(".gif", Qt::CaseInsensitive)
|| fn.endsWith(".pbm", Qt::CaseInsensitive)
|| fn.endsWith(".pgm", Qt::CaseInsensitive)
|| fn.endsWith(".ppm", Qt::CaseInsensitive)
|| fn.endsWith(".xbm", Qt::CaseInsensitive)
|| fn.endsWith(".xpm", Qt::CaseInsensitive)
|| fn.endsWith(".svg", Qt::CaseInsensitive))) {
QMessageBox::warning(this, tr("自动出卷系统"), tr("不支持的文件格式。"));
return;
}
QTextEdit *pEdit = textEditor.editor;
QTextCursor cursor = pEdit->textCursor();
QTextImageFormat imageFormat;
imageFormat.setName(fn);
//pEdit->setText();
cursor.insertImage(imageFormat);
}