Nominate our 2022 Qt Champions!

Displaying a Pixmap on a Graphics View Widget

  • In the code below I am trying to display a diagonal line on a Graphics View widget that I have already dropped onto a form in the Qt Creator. I am having trouble getting the .cpp form to actually know of the existence of my Graphics View Widget. It seems as though; just shows a ambiguous GraphicView Object. I have tried using the same name for my GraphicView widget on the form in the code (PixmapView) instead of view, but .cpp does not know of it's existence. Is there a way to render this? An onCreate signal would be great but I don't believe this exists.

    //CanvasTest::CanvasTest(QWidget *parent) :
        ui(new Ui::CanvasTest)
        QPixmap pm(200,200);
        QPainter pmp(&pm);
        int counter = 0;
        while (counter < 200)
        QGraphicsScene scene;
        QGraphicsPixmapItem item(pm);
        QGraphicsView view(&scene);;

  • should the Qt Creator generated #include <ui_Canvastest.h> allow me to access objects in the canvas_ui form code sheet? I can see that there is an object of type Graphics View named PixMapView (what I named my widget/object as) in the canvas_ui form code. Is there a way to access this object in the .cpp code?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Since your widgett is called PixmapView then in your CanvaTest class you can use ui->PixmapView ..