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 view.show(); 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) : QMainWindow(parent), ui(new Ui::CanvasTest) { ui->setupUi(this); QPixmap pm(200,200); QPainter pmp(&pm); pmp.setPen(Qt::black); int counter = 0; while (counter < 200) { pmp.drawPoint(counter,counter); counter++; } pmp.end(); QGraphicsScene scene; QGraphicsPixmapItem item(pm); scene.addItem(&item); QGraphicsView view(&scene); view.show();
-
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?
-
Hi and welcome to devnet,
Since your widgett is called PixmapView then in your CanvaTest class you can use
ui->PixmapView
..