Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to draw QGraphicsPolygonItem
Qt 6.11 is out! See what's new in the release blog

how to draw QGraphicsPolygonItem

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 3 Posters 2.7k Views 1 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #5

    Hi
    Its very good you use qDebug() but would be even nicer if you added some text so
    its easier to follow what is what.

    qDebug() <<"graphicsView::addPoint - qv_points: " << qv_points;

    Anyway, it looks very odd as list suddenly is empty.
    It looks all is inside same class so unless you call clear on it
    i see no way it suddenly goes empty.

    However, looking at the posted code, there is also nowhere - where you add to the qv_points list.

    H 2 Replies Last reply
    0
    • mrjjM mrjj

      Hi
      Its very good you use qDebug() but would be even nicer if you added some text so
      its easier to follow what is what.

      qDebug() <<"graphicsView::addPoint - qv_points: " << qv_points;

      Anyway, it looks very odd as list suddenly is empty.
      It looks all is inside same class so unless you call clear on it
      i see no way it suddenly goes empty.

      However, looking at the posted code, there is also nowhere - where you add to the qv_points list.

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

      @mrjj is there anyway to debug like in visual studio where you can step over etc.?

      I would just like to see what qv_points does with each action.

      1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        Its very good you use qDebug() but would be even nicer if you added some text so
        its easier to follow what is what.

        qDebug() <<"graphicsView::addPoint - qv_points: " << qv_points;

        Anyway, it looks very odd as list suddenly is empty.
        It looks all is inside same class so unless you call clear on it
        i see no way it suddenly goes empty.

        However, looking at the posted code, there is also nowhere - where you add to the qv_points list.

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

        @mrjj said in how to draw QGraphicsPolygonItem:

        However, looking at the posted code, there is also nowhere - where you add to the qv_points list.

        the first line of addPoint() is where the point is added to the qv_points.

        void graphicsView::addPoint(QPointF pos)
        {
            qv_points << pos;
        
        mrjjM 1 Reply Last reply
        0
        • H hobbyProgrammer

          @mrjj said in how to draw QGraphicsPolygonItem:

          However, looking at the posted code, there is also nowhere - where you add to the qv_points list.

          the first line of addPoint() is where the point is added to the qv_points.

          void graphicsView::addPoint(QPointF pos)
          {
              qv_points << pos;
          
          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #8

          @hobbyProgrammer
          Hi
          Ah i miss that as i was looking for append or similar :)

          Yes, just start the app in debug mode (f5)
          Then place a break point.
          Then press F10 to step or F11

          H 2 Replies Last reply
          0
          • mrjjM mrjj

            @hobbyProgrammer
            Hi
            Ah i miss that as i was looking for append or similar :)

            Yes, just start the app in debug mode (f5)
            Then place a break point.
            Then press F10 to step or F11

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

            @mrjj oh thanks!

            I got the error: Unable to create a debugging engine.
            but I didn't have any debuggers for MSVC. I did have two for minGW so I added those kits to my project and now I can view them hopefully.

            1 Reply Last reply
            0
            • mrjjM mrjj

              @hobbyProgrammer
              Hi
              Ah i miss that as i was looking for append or similar :)

              Yes, just start the app in debug mode (f5)
              Then place a break point.
              Then press F10 to step or F11

              H Offline
              H Offline
              hobbyProgrammer
              wrote on last edited by
              #10
              This post is deleted!
              1 Reply Last reply
              0
              • H Offline
                H Offline
                hobbyProgrammer
                wrote on last edited by hobbyProgrammer
                #11

                @mrjj
                I managed to see that it shows up empty in the addPolygon function, but when I add a new point it still shows the old points in the debugger.

                This is what I get in the debugger:

                qv_points in addPoint:  QVector(QPointF(27,40))
                qv_points in addPoint:  QVector(QPointF(27,40), QPointF(50,229))
                qv_points in addPoint:  QVector(QPointF(27,40), QPointF(50,229), QPointF(151,236))
                qv_points in addPoint:  QVector(QPointF(27,40), QPointF(50,229), QPointF(151,236), QPointF(152,147))
                addPoly() qv_points:  QVector()
                addPoly() qv_points:  QVector()
                addPoly() qv_points:  QVector()
                qv_points in addPoint:  QVector(QPointF(27,40), QPointF(50,229), QPointF(151,236), QPointF(152,147), QPointF(245,129))
                
                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #12

                  hi
                  The debugger for visual studio is a separate download called
                  Debugging tools from MS.

                  When you press Ctrl+N , you are not creating a new instance of the
                  graphicsView or something like that ?

                  H 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    hi
                    The debugger for visual studio is a separate download called
                    Debugging tools from MS.

                    When you press Ctrl+N , you are not creating a new instance of the
                    graphicsView or something like that ?

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

                    @mrjj yes I did! Thank you so much.

                    I had this in the create actions

                    GraphicsView gv = new GraphicsView;
                    
                    
                        addPolyAct = new QAction(tr("&Add Poly..."), this);
                        addPolyAct->setShortcut(QKeySequence::New);
                        connect(addPolyAct, SIGNAL(triggered()), gv , SLOT(addPoly()));
                    

                    since I promoted the widget inside the designer I changed it to:

                        addPolyAct = new QAction(tr("&Add Poly..."), this);
                        addPolyAct->setShortcut(QKeySequence::New);
                        connect(addPolyAct, SIGNAL(triggered()), ui->graphicsView, SLOT(addPoly()));
                    

                    Now everything works perfectly!
                    Thank you so much.

                    mrjjM 1 Reply Last reply
                    1
                    • H hobbyProgrammer

                      @mrjj yes I did! Thank you so much.

                      I had this in the create actions

                      GraphicsView gv = new GraphicsView;
                      
                      
                          addPolyAct = new QAction(tr("&Add Poly..."), this);
                          addPolyAct->setShortcut(QKeySequence::New);
                          connect(addPolyAct, SIGNAL(triggered()), gv , SLOT(addPoly()));
                      

                      since I promoted the widget inside the designer I changed it to:

                          addPolyAct = new QAction(tr("&Add Poly..."), this);
                          addPolyAct->setShortcut(QKeySequence::New);
                          connect(addPolyAct, SIGNAL(triggered()), ui->graphicsView, SLOT(addPoly()));
                      

                      Now everything works perfectly!
                      Thank you so much.

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

                      @hobbyProgrammer

                      Ok. Good. :)
                      It was my only guess
                      how on earth the points list could become
                      empty.
                      Sometimes Im a lucky guesser :)

                      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
                      • Unsolved