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. Use qtDesigner for create a Cartesian plane

Use qtDesigner for create a Cartesian plane

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 4.1k 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.
  • R Offline
    R Offline
    rikytres
    wrote on last edited by
    #1

    Hi everyone!

    I'm searching for a solution to create a Cartesian Plane, using qtDesigner.

    I find out QGraphicView and QGraphicScene for creating a "canvas" and the cartesian axes (and also all geometric shapes) but I don't know how to do this.

    PS:
    I find this code for create a simple triangle
    @ QGraphicsScene* scene = new QGraphicsScene();
    scene->addLine(0, 0, 50, 0);
    scene->addLine(50, 0, 50, 50);
    scene->addLine(50, 50, 0, 0);
    QGraphicsView* view = new QGraphicsView(scene);@
    But I don't know how to connect this code to a QGraphicsView on a qtDesiner form.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      Are you saying you want to use designer to draw QGraphicsScene elements manually?

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rikytres
        wrote on last edited by
        #3

        No, I'm sorry... I did not explain well...
        I going to do better.

        I have a QMainWindow with a QLineEdit where i can input some point, line or triangle.
        I want to create a QPushButton that plot the input on a canvas.

        I'm used qtDesigner for create my form, and i prefer to continue to using it.
        Then i add to my form a QGraphicView and i try to add a QGraphicScene to it but i didn't.

        PS: I hope now you understand. I can't explain better because I can't speak english very well...

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          You can use designer to add your QGraphicsView widget, as you did. However, I believe you'll have to write the code yourself to add a slot which does the work you desire. Designer is a great tool for designing the layout of widgets, but it isn't intended to add the rest of the logic and other non-widget items.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rikytres
            wrote on last edited by
            #5

            Ok, is that I did.

            I add a QGraphicsView and a QPushButton using designer.
            Now I have to create a slot for the button that add a QGraphicScene to the graphicView.
            Can this be a example of the slot?
            @void mineSlots(){

            //get the object to plot here
            
            QGraphicsScene* scene = new QGraphicsScene();
            //exemple of an object to plot
            scene->addLine(0, 0, -50, 0);
            scene->addLine(-50, 0, -50, -50);
            scene->addLine(-50, -50, 0, 0);
            
            this->graphicsView->setScene(scene);
            

            }
            @

            1 Reply Last reply
            0
            • M Offline
              M Offline
              marsupial
              wrote on last edited by
              #6

              yes, although as far as I know, the graphicsView does not take ownership of the scene. Thus, if the user presses the button again, the old scene doesn't get deleted.

              So either don't create a new scene every time the user presses the button (but instead, just add the points to the existing scene) or somehow store the scene and remove the old one after creating a new one ;)

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mlong
                wrote on last edited by
                #7

                If you create a new scene every time, you may run into a memory leak if you don't get rid of the old one first. You might consider creating the scene in the constructor, then just reusing it every time you need to.

                Software Engineer
                My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  rikytres
                  wrote on last edited by
                  #8

                  Ok! Thanks a lot! I'm gonna try!

                  If I have other problems i will ask! ;)

                  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