Skip to content
  • 144k Topics
    723k Posts
    D
    Hello I'm making an interactive report generator based on RichText handling and editing, I have content with text, tables and images, my QML part is TextArea, and in C++ QQuickTextDocument and QTextDocument When I paste html into TextArea, all the images of the table and text are visible, but when I give it to QPrinter and output the preview to QPrintPreviewDialog, I have there are no images, here are my 2 approaches for adding images. In the first case, I converted to base64 and stuffed it into Html, but it doesn't work.: void ReportBuilder::addInlineImageElement(const QImage &image, qreal width, qreal height) { QString style; if (width > 0) style += QString("width:%1px;").arg(width); if (height > 0) style += QString("height:%1px;").arg(height); if (width == 0 && height == 0) style += "max-width:100%;height:auto;"; QString imgTag = QString("<img width='%1' src='data:image/png;base64,%2'/>") .arg(width) .arg(imageToBase64(image)); append(imgTag); } QString ReportBuilder::imageToBase64(const QImage &image) { QImage scaled = image.scaled(640, 640, Qt::KeepAspectRatio, Qt::SmoothTransformation); QByteArray ba; QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); scaled.save(&buffer, "PNG"); return QString::fromLatin1(ba.toBase64()); } My second way is to add my images to the QTextDocument resources, I generate a QUrl, send a QUrl and a QImage to a model that inserts html into the QTextDocument, but before that it registers the images, but for some reason it doesn't work either: void ReportBuilder::addImageElement(const QImage &image, qreal width, qreal height) { QImage scaled = image.scaled(640, 640, Qt::KeepAspectRatio, Qt::SmoothTransformation); m_imageCounter++; QString imageName = QString("image_%1.jpg").arg(m_imageCounter); QString resourceUrl = QString("cid_%1").arg(imageName); QUrl imgUrl(QString("myimg://%1").arg(resourceUrl)); m_images.insert(imgUrl, scaled); QString imgTag = QString("<img src=\"%1\"/>").arg(imgUrl.toString()); qDebug()<<imgTag; m_html.append(imgTag); } void ReportEditorModel::insertReport(const QString &html, const QMap<QUrl, QImage> &images) { QTextDocument *doc = textDocument(); if (!doc) { qWarning() << "No document available to insert Report."; return; } for (auto it = images.constBegin(); it != images.constEnd(); ++it) { doc->addResource(QTextDocument::ImageResource, QUrl(it.key()), it.value()); } QTextCursor cursor = textCursor(); QString wrappedHtml = QString("<div style='" "margin-left:%1px;" "margin-right:%2px;" "margin-top:%3px;" "margin-bottom:%4px;'>" "%5" "</div>") .arg(m_leftMargin) .arg(m_rightMargin) .arg(m_topOffset) .arg(m_bottomOffset) .arg(html); // cursor.movePosition() cursor.insertHtml(wrappedHtml); QPrinter printer(QPrinter::HighResolution); QPrintPreviewDialog preview(&printer); connect(&preview, &QPrintPreviewDialog::paintRequested, this, [this, doc](QPrinter *printer){doc->print(printer);}); preview.exec(); } Here is my curent html: "<div style='margin-left:85.0394px;margin-right:85.0394px;margin-top:85.0394px;margin-bottom:85.0394px;'> <div style='font-size:10pt;'></div> <hr /> <div style='font-size:16pt;'>Image 1.jpg</div> <hr /> <div style='font-size:10pt;'></div> <img src=\"myimg://cid_image_1.jpg\"/> <div style='font-size:10pt;'></div> <hr /> <div style='font-size:16pt;'>Info</div> <hr /> <div style='font-size:10pt;'>Name: Image 1.jpg</div> <div style='font-size:10pt;'>Size: 1824x446</div> <div style='font-size:10pt;'>Resolution: 623 dpi</div> <div style='font-size:10pt;'>Bit depth: 24 bit(s)</div> <div style='font-size:10pt;'>Creation time: 14:24:07 03.09.2024</div> </div>" Any ideas how to make it work? Currently on Qt 6.2.0, but on 6.5.3 same situation.
  • Jobs, project showcases, announcements - anything that isn't directly development
    4k 23k
    4k Topics
    23k Posts
    S
    @RokeJulianLockhart From what it looks like, QT is still being used on both Windows and macOS for the drop-down that shows recently synced files (and other parts of the app that look identical cross-platform). However, OneDrive's settings page appears to be using React Native on both platforms (Windows/macOS) to render native XAML/AppKit components on their respective platforms.
  • Everything related to designing and design tools

    127 383
    127 Topics
    383 Posts
    R
    I see this is an old thread and I see several unresolved threads on this topic. I'm leaving this incase it helps someone else who ends up here. The solution was twofold for me. Go to File > Export Project and select Enable Python Generator. This will create a main.py. Make sure you pip install PySide6-DS Hope this helps someone.
  • Everything related to the QA Tools

    77 213
    77 Topics
    213 Posts
    J
    Hello i am using WinCC OA to develop a qt application. WinCC OA has some custom elements which cannot be detected by squish for example a polygon. Squish is now not able to detect this element with the picker. I know the name of the element but as it is of WinCC OA internal i do not know the type: waitForObject( {"container": "container", "name": "POLYGON1","type": "???","visible": 1} ); How do i get this information? And what to use if unknown? Is there any other way? I mainly just need to click this element. Thanks a lot
  • Everything related to learning Qt.

    382 2k
    382 Topics
    2k Posts
    V
    Thank you 😊
  • 2k Topics
    13k Posts
    SGaistS
    Oh right, I forgot about that one. Depending on the content you can apply the same to rows. In any case, since your issue is fixed, please mark the thread as solved using the "Topic Tools" button so that other forum members may know a solution has been found :-)
  • 4k Topics
    18k Posts
    M
    @Max Ok, j'ai compris : en modifiant la taille de la fonte du QLineEdit inclus dans le QTimeEdit, ça fonctionne. Bêtement je prenais la police "f" du QLineEdit inclus, modifiais la taille de "f" et faisais QLineEdit->parent->setFont(f). Ici "parent" était de trop. En me relisant, j'espère que ce que j'ai écris est compréhensible... A+ Sylvain
  • This is where all the posts related to the Qt web services go. Including severe sillyness.
    1k 10k
    1k Topics
    10k Posts
    SGaistS
    @RokeJulianLockhart to the best of my knowledge, no. The first release of Discourse was in 2014 and the forum is several years older than that.