[Solved] How to get a Preview into a QDialog

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
333onlyhalfevil
Full Member
Posts: 97
Joined: Fri Apr 28, 2023 12:39 pm

[Solved] How to get a Preview into a QDialog

Post by 333onlyhalfevil » Wed Jan 21, 2026 1:41 pm

Hello everyone:

I'm trying to get one of my scripts to add a preview into a dialog box but it doesn't seem to want to display anything. Note that I'm not necessarily talking about the "preview" in terms of your script showing some entities where your mouse is, for example. I want to show the entities in a qgraphicsview widget within a dialog box. Here's the code I have so far while trying to figure it out myself:

Code: Select all

var previewRMemoryStorage = new RMemoryStorage();
    var previewRSpatialIndexNavel = new RSpatialIndexNavel();
    var previewRDocument = new RDocument(previewRMemoryStorage, previewRSpatialIndexNavel);
    var previewRDocumentInterface = new RDocumentInterface(previewRDocument);
    addRLineEntityToRDocument(previewRDocument, previewRDocumentInterface, previewRLineEntity);
    var previewRGraphicsSceneQt = new RGraphicsSceneQt(previewRDocumentInterface);
    var previewRGraphicsViewImage = new RGraphicsViewImage();
    previewRGraphicsViewImage.setScene(previewRGraphicsSceneQt);
    var previewQPainter = new QPainter();
    previewQPainter.pen = Qt.blue;
    previewQPainter.width = 1;
    previewQPainter.setFont(new QFont("Arial", 30));
    previewRGraphicsViewImage.paintEntities(previewQPainter, new RBox(new RVector(0.4, 129), new RVector(0.63, 171)));
    previewRGraphicsViewImage.repaintView();
    var previewQImage = previewRGraphicsViewImage.getGraphicsBufferWithPreview();
    var previewQGraphicsScene = new QGraphicsScene();
    var previewQPixmap = QPixmap.fromImage(previewQImage);
    previewQGraphicsScene.addPixmap(previewQPixmap);
    previewQWidgets["PreviewQGraphicsView"].setScene(previewQGraphicsScene);
I'm basically creating a dummy document and document interface and adding the line to it, then trying to extract a QImage of the scene out of the dummy document. The above code runs without any errors but the QGraphicsView widget within the dialog box remains blank. Any ideas as to how I could get this to work?
Last edited by 333onlyhalfevil on Wed Jan 21, 2026 3:44 pm, edited 1 time in total.

CVH
Premier Member
Posts: 5112
Joined: Wed Sep 27, 2017 4:17 pm

Re: How to get a Preview into a QDialog?

Post by CVH » Wed Jan 21, 2026 2:23 pm

Hi,

I think you may want to investigate how the Hatch dialog works.
That shows a rectangular hatched area.
A view of a limited part of an off-screen document.

The it is quite similar as like creating things on a document.

Regards,
CVH
Last edited by CVH on Fri Jan 23, 2026 10:06 am, edited 1 time in total.

333onlyhalfevil
Full Member
Posts: 97
Joined: Fri Apr 28, 2023 12:39 pm

Re: How to get a Preview into a QDialog?

Post by 333onlyhalfevil » Wed Jan 21, 2026 3:44 pm

Yes, this was helpful. I got it working now. Thank you.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”