当前位置: 首页>>代码示例>>C++>>正文


C++ QTextDocument::addResource方法代码示例

本文整理汇总了C++中QTextDocument::addResource方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocument::addResource方法的具体用法?C++ QTextDocument::addResource怎么用?C++ QTextDocument::addResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTextDocument的用法示例。


在下文中一共展示了QTextDocument::addResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: on_actionImage_triggered

/**
 * Inserts an valid image
 * Copies the specific image in the program folder
 */
void MainWindow::on_actionImage_triggered()
{
    QString scriboDir = QDir::home().absolutePath() + QDir::separator() + "scribo";

    if ( !QDir(scriboDir + QDir::separator() + "img").exists() )
        QDir().mkdir(scriboDir + QDir::separator() + "img");

    QString filePath = QFileDialog::getOpenFileName(this, tr("Select an image"),
                                      QDir::home().absolutePath(), "Bitmap Files (*.bmp)\n"
                                        "JPEG (*.jpg *jpeg)\n"
                                        "GIF (*.gif)\n"
                                        "PNG (*.png)");
    QStringList list = filePath.split( "/" );
    QString imageName = list.value(list.length() - 1 );
    QString imagePath = scriboDir + QDir::separator() + "img" + QDir::separator() + imageName;

    QFile::copy(filePath, imagePath);
    QUrl Uri ( QString ( "file://%1" ).arg ( imagePath ) );
    QImage image = QImageReader ( imagePath ).read();

    QTextDocument * textDocument = ui->textEdit_mainWindow_surface->document();
    textDocument->addResource( QTextDocument::ImageResource, Uri, QVariant ( image ) );
    cursor = ui->textEdit_mainWindow_surface->textCursor();
    QTextImageFormat imageFormat;
    imageFormat.setWidth( image.width() );
    imageFormat.setHeight( image.height() );
    imageFormat.setName( Uri.toString() );
    cursor.insertImage(imageFormat);
}
开发者ID:1cy1c3,项目名称:scribo,代码行数:33,代码来源:mainwindow.cpp

示例2: 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);
	});
	

};
开发者ID:sunRainPenguin,项目名称:libdash-adaptation,代码行数:27,代码来源:CommentDialog.cpp

示例3: image

QPair< QString, QSize > TextEdit::Private::addImageResource( const QString & fileName, const QUrl & uri ) {
    QTextDocument * document = this->host->document();
    QImage image( QImage( uri.toLocalFile() ).scaled( 50, 50, Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
    document->addResource( QTextDocument::ImageResource, QUrl( fileName ), image );

    return qMakePair( fileName, image.size() );
}
开发者ID:ncuoolab,项目名称:xtitan,代码行数:7,代码来源:TextEdit.cpp

示例4: QTextDocument

QTextDocument *KisNodeToolTip::createDocument(const QModelIndex &index)
{
    QTextDocument *doc = new QTextDocument(this);

    QImage thumb = index.data(int(KisNodeModel::BeginThumbnailRole) + 250).value<QImage>();
    doc->addResource(QTextDocument::ImageResource, QUrl("data:thumbnail"), thumb);

    QString name = index.data(Qt::DisplayRole).toString();
    KisBaseNode::PropertyList properties = index.data(KisNodeModel::PropertiesRole).value<KisBaseNode::PropertyList>();
    QString rows;
    const QString row = QString("<tr><td align=\"right\">%1:</td><td align=\"left\">%2</td></tr>");
    QString value;
    for(int i = 0, n = properties.count(); i < n; ++i) {
        if (properties[i].isMutable)
            value = properties[i].state.toBool() ? i18n("Yes") : i18n("No");
        else
            value = properties[i].state.toString();

        rows.append(row.arg(properties[i].name).arg(value));
    }

    rows = QString("<table>%1</table>").arg(rows);

    const QString image = QString("<table border=\"1\"><tr><td><img src=\"data:thumbnail\"></td></tr></table>");
    const QString body = QString("<h3 align=\"center\">%1</h3>").arg(name)
                       + QString("<table><tr><td>%1</td><td>%2</td></tr></table>").arg(image).arg(rows);
    const QString html = QString("<html><body>%1</body></html>").arg(body);

    doc->setHtml(html);
    doc->setTextWidth(qMin(doc->size().width(), qreal(500.0)));

    return doc;
}
开发者ID:hshrimali,项目名称:krita,代码行数:33,代码来源:KisNodeToolTip.cpp

示例5: 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");
    }
}
开发者ID:CodeDJ,项目名称:qt5-hidpi,代码行数:12,代码来源:textedit.cpp

示例6: insertImg

void ChatLogWin::insertImg(const QString &img_name)
{
    QTextDocument *doc = ui_->msgbrowse->document();
    QTextCursor cursor(doc);
    cursor.movePosition(QTextCursor::End);

    QImage img(QQGlobal::tempDir() + "/" + img_name);
    QUrl url(img_name);
    doc->addResource(QTextDocument::ImageResource, url, img);
    cursor.insertImage(img_name);
}
开发者ID:Akers,项目名称:Qtqq,代码行数:11,代码来源:chatlogwin.cpp

示例7: insertImg

void QQTextEdit::insertImg(const QString &url, const QString &path)
{
    QTextDocument *doc = document();
    QTextCursor cursor(doc);
    cursor.movePosition(QTextCursor::End);

    QImage img(path);
    QUrl qurl(url);
    doc->addResource(QTextDocument::ImageResource, qurl, img);
    cursor.insertImage(url);
}
开发者ID:GHfangxin,项目名称:Qtqq,代码行数:11,代码来源:qqtextedit.cpp

示例8: reloadResource

void Dialog::reloadResource(QTextEdit *ed) {
    QTextDocument *doc = ed->document();
    int w = smiles->size().width() / W_CNT;
    int h = smiles->size().height() / H_CNT;
    for (int i = 0; i < W_CNT; ++i)
        for (int j = 0; j < H_CNT; ++j) {
            QImage icon = smiles->copy(j * w, i * h, w, h);
            QString nm = "[smile:" + QString::number(W_CNT * i + j) + "]";
            doc->addResource(QTextDocument::ImageResource, QUrl(nm), icon);
            //teHistory->document()->addResource(QTextDocument::ImageResource, QUrl(but->name()), smiles->copy(j * w, i * h, w, h));
        }
}
开发者ID:pva701,项目名称:codes,代码行数:12,代码来源:dialog.cpp

示例9: insertQQFace

void ChatLogWin::insertQQFace(const QString &face_id)
{
    QTextDocument *doc = ui_->msgbrowse->document();
    QTextCursor cursor(doc);
    cursor.movePosition(QTextCursor::End);

    QString path = QQGlobal::resourceDir() + "/qqface/default/" + face_id + ".gif";
    QImage img(path);
    QUrl url(face_id);
    doc->addResource(QTextDocument::ImageResource, url, img);
    cursor.insertImage(face_id);
}
开发者ID:Akers,项目名称:Qtqq,代码行数:12,代码来源:chatlogwin.cpp

示例10: insertQQFace

void QQTextEdit::insertQQFace(const QString &face_id)
{
    QTextDocument *doc = document();
    QTextCursor cursor(doc);
    cursor.movePosition(QTextCursor::End);

    QString path = QQGlobal::resourceDir() + "/qqface/default/" + face_id + ".gif";
    QImage img(path);
    QString src = kQQFacePre+face_id;
    QUrl url(src);
    doc->addResource(QTextDocument::ImageResource, url, img);
    cursor.insertImage(src);
}
开发者ID:GHfangxin,项目名称:Qtqq,代码行数:13,代码来源:qqtextedit.cpp

示例11: insertDecoration

void FillCellHelper::insertDecoration( KDReports::ReportBuilder& builder, QTextDocument& textDoc )
{
    QImage img = qvariant_cast<QImage>( cellDecoration );
    if ( img.isNull() ) {
        img = qvariant_cast<QIcon>( cellDecoration ).pixmap( iconSize ).toImage();
    }
    if ( !img.isNull() ) {
        static int imageNumber = 0;
        const QString name = QString::fromLatin1( "cell-image%1.png" ).arg( ++imageNumber );
        textDoc.addResource( QTextDocument::ImageResource, QUrl( name ), img );
        builder.currentDocumentData().addResourceName( name );
        cellCursor.insertImage( name );
    }
}
开发者ID:,项目名称:,代码行数:14,代码来源:

示例12: requestFinished

void ImageTextBrowser::requestFinished(QNetworkReply * result)
{
    if (!result->error())
    {
        QByteArray res = result->readAll();
        QPixmap pixmap;
        pixmap.loadFromData(res);
        QImage img = pixmap.toImage();

        QTextDocument *doc = this->document();
        doc->addResource(QTextDocument::ImageResource,result->url(),QVariant(img));
        setHtml(toHtml());
        QScrollBar * vBar = this->verticalScrollBar();
        vBar->setValue(vBar->maximum());
    }
}
开发者ID:SpaceWind,项目名称:cyber_jihad_bot_client,代码行数:16,代码来源:imagetextbrowser.cpp

示例13: stressTestPaint

void QTextPanel::stressTestPaint()
{
    /////////pageClear();  /* remove all if exist text */
    
    
    QTextDocument *playdoc = new QTextDocument();
    QTextCursor c(playdoc);
    c.setPosition(0,QTextCursor::MoveAnchor);
    
    int loop = -1;
    c.beginEditBlock();
    
    QStringList colorNames = QColor::colorNames();
    foreach (QString name, colorNames) {
        loop++;
        
        if (loop != 0) { 
        c.insertBlock();
        }
        
        ////////qDebug() << "### name ->" << name;
        
        QPixmap e = createColorMaps( name );
        playdoc->addResource(QTextDocument::ImageResource,QUrl(name),e);
        QTextImageFormat format;
        format.setName( name );
        format.setHeight ( e.height() );
        format.setWidth ( e.width() );
        format.setToolTip(name);
        c.insertImage( format );
        c.insertText(QString(QChar::LineSeparator));   /* br */
        ////////////QTextBlockFormat bbformat = c.blockFormat();
        /////////bbformat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysAfter);
        ////////c.setBlockFormat(bbformat);
        
        for (int i = 0; i < 15; ++i)  {
        c.insertText(name+ "   .");   
        }
        c.endEditBlock();
        c.atBlockEnd();
        
    }
开发者ID:SorinS,项目名称:fop-miniscribus,代码行数:42,代码来源:qtextpanel.cpp

示例14: 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");
        }
    }
开发者ID:GrandHsu,项目名称:pyside2,代码行数:20,代码来源:textedit.cpp

示例15: 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
}
开发者ID:CharlesHoskinson,项目名称:keyhotee,代码行数:20,代码来源:MailViewer.cpp


注:本文中的QTextDocument::addResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。