Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Displaying a Pixmap on a Graphics View Widget
QtWS25 Last Chance

Displaying a Pixmap on a Graphics View Widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
graphics viewpixmapqt creatorqpaintqgraphicsview
3 Posts 2 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brazzoni
    wrote on 14 Jul 2017, 17:39 last edited by
    #1

    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();
    
    
    B 1 Reply Last reply 14 Jul 2017, 19:08
    0
    • B Brazzoni
      14 Jul 2017, 17:39

      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();
      
      
      B Offline
      B Offline
      Brazzoni
      wrote on 14 Jul 2017, 19:08 last edited by
      #2

      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?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 14 Jul 2017, 22:02 last edited by
        #3

        Hi and welcome to devnet,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2

        2/3

        14 Jul 2017, 19:08

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved