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. drawing shapes onto QPixmap with QPaintEvent
Forum Updated to NodeBB v4.3 + New Features

drawing shapes onto QPixmap with QPaintEvent

Scheduled Pinned Locked Moved Unsolved General and Desktop
24 Posts 3 Posters 5.2k Views 2 Watching
  • 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.
  • H hobbyProgrammer

    @mrjj yes exactly! but when I zoom in and out I would like there to be a scrollbar so that I can view and edit the entire image and not just the upper part.

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #21

    @hobbyProgrammer

    Well im asking as you use the GraphicsView in a (in my opinion) odd way
    as you treat it like the QWidget paint.
    Normally one would use
    https://doc.qt.io/qt-5/qgraphicspixmapitem.html
    for the image and and make a custom QGraphicsItem to handle the overlay points
    and in other ways used the features of the QGraphicsScene/view.

    Where are you seem to directly draw on the view as a normal Widget.

    Its not criticism! i just wondered if you needed all of the QGraphicsScene/view stuff as doing with just a QWidget and paint is far more simple if
    all the other features is not needed.

    And when you just overwrite paint for view (as the code you shown), then you are not using ANY of the selection/grouping/scaling etc of the Graphics Framework.
    So i had to ask :)

    H 1 Reply Last reply
    1
    • mrjjM mrjj

      @hobbyProgrammer

      Well im asking as you use the GraphicsView in a (in my opinion) odd way
      as you treat it like the QWidget paint.
      Normally one would use
      https://doc.qt.io/qt-5/qgraphicspixmapitem.html
      for the image and and make a custom QGraphicsItem to handle the overlay points
      and in other ways used the features of the QGraphicsScene/view.

      Where are you seem to directly draw on the view as a normal Widget.

      Its not criticism! i just wondered if you needed all of the QGraphicsScene/view stuff as doing with just a QWidget and paint is far more simple if
      all the other features is not needed.

      And when you just overwrite paint for view (as the code you shown), then you are not using ANY of the selection/grouping/scaling etc of the Graphics Framework.
      So i had to ask :)

      H Offline
      H Offline
      hobbyProgrammer
      wrote on last edited by
      #22

      @mrjj okay, but I still don't get how to use the QGraphicsScene/View now.
      Do I make the ScrollArea a QGraphicsView and then load the QGraphicsPixmap into the QGraphicsView?

      I don't really get the structure that is needed for this.

      mrjjM 1 Reply Last reply
      0
      • H hobbyProgrammer

        @mrjj okay, but I still don't get how to use the QGraphicsScene/View now.
        Do I make the ScrollArea a QGraphicsView and then load the QGraphicsPixmap into the QGraphicsView?

        I don't really get the structure that is needed for this.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #23

        @hobbyProgrammer

        Hi
        Normally the one would use QGraphicsPixmapItem
        and maybe a custom item for the lines/polygon.
        You would not need a ScrollArea

        H 1 Reply Last reply
        0
        • mrjjM mrjj

          @hobbyProgrammer

          Hi
          Normally the one would use QGraphicsPixmapItem
          and maybe a custom item for the lines/polygon.
          You would not need a ScrollArea

          H Offline
          H Offline
          hobbyProgrammer
          wrote on last edited by
          #24

          @mrjj Okay so I tried to make a new graphicsview and this is the code.
          It doesn't seem to load the pixmap.
          It's probably a stupid mistake (I make them a lot), since I've wasted way too much time on this.

          #include "graphicsview.h"
          
          GraphicsView::GraphicsView(QWidget *parent)
              : QGraphicsView(parent)
          {
              scene = new QGraphicsScene(this);
              setScene(scene);
          }
          
          void GraphicsView::open()
          {
              filename = QFileDialog::getOpenFileName(this,tr("Open File"), QDir::currentPath(), tr("Image Files(*.png *.jpg *.jpeg)"));
              qDebug() << filename;
              QGraphicsPixmapItem *pixmap = scene->addPixmap(QPixmap(filename));
              update();
          }
          
          1 Reply Last reply
          0

          • Login

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