本文整理汇总了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);
}
示例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);
});
};
示例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() );
}
示例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;
}
示例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");
}
}
示例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);
}
示例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);
}
示例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));
}
}
示例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);
}
示例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);
}
示例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 );
}
}
示例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());
}
}
示例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();
}
示例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");
}
}
示例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
}