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. Creating a coordinate system in Qt

Creating a coordinate system in Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.5k 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.
  • E Offline
    E Offline
    El3ctroGh0st
    wrote on 23 Mar 2018, 17:18 last edited by
    #1

    Hello,

    so this is less a question about a specific programming error I'm getting, but more about how to design the concept I want to implement best. So what I want to create is a coordinate system with basic functionalities (similar to the one in the program Geogebra, in case you have heard of it):0_1521825119318_699a0f2c-9bd9-4f44-aa1d-0d19b1e0d914-image.png

    What is important that one can indefinitely drag (I'm emphasising this because I know that you could do this with a scroll bar, but I havent found out how I can do this with a simple click-and-drag feature) up/down and sideways. And this is what I have been having issues with. This is what I have so far (as you can see, it's far from perfect yet haha):0_1521825317680_78fc63d5-947d-41f1-8e4b-1082111e85a6-image.png

    My main issue is that I don't know how I can implement the "scroll indefinitely" feature. So basically what I'm doing right now is using a GraphicsScene + GraphicsView and a bunch of lines to draw the grid. But I am sure that this is not very efficient and there is a better way to do this. Does anybody have some tips? Note that I am not asking for someone to write the code for me, I just want to know some possible approaches to this. I hope someone can help me!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 23 Mar 2018, 17:25 last edited by
      #2

      Hi
      Are you using
      http://doc.qt.io/qt-5/qgraphicsscene.html#drawBackground
      ?

      E 1 Reply Last reply 23 Mar 2018, 17:30
      0
      • M mrjj
        23 Mar 2018, 17:25

        Hi
        Are you using
        http://doc.qt.io/qt-5/qgraphicsscene.html#drawBackground
        ?

        E Offline
        E Offline
        El3ctroGh0st
        wrote on 23 Mar 2018, 17:30 last edited by
        #3

        @mrjj Oh, no am I not. Right now I am kind of... drawing them manually, like this:

        void CoordinateGrid::drawAxis()
        {
            QPen axisPen(Qt::black);
            axisPen.setWidth(2);
        
            xAxis = graphicsScene->addLine(0, winSize.height()/2, winSize.width(), winSize.height()/2, axisPen);
            yAxis = graphicsScene->addLine(winSize.width() / 2, 0, winSize.width() / 2, winSize.height(), axisPen);
        }
        
        void CoordinateGrid::drawGrid()
        {
            QPen gridPen(Qt::gray);
            gridPen.setWidth(1);
        
            int boxSize = 40;
        
            for(int i = 1; i*boxSize <= winSize.height()/2; ++i)
            {
                graphicsScene->addLine(0, winSize.height()/2 - boxSize*(i), winSize.width(), winSize.height()/2 - boxSize*(i), gridPen);
                graphicsScene->addLine(0, winSize.height()/2 + boxSize*(i), winSize.width(), winSize.height()/2 + boxSize*(i), gridPen);
            }
        
            for(int i = 1; i*boxSize <= winSize.width()/2; ++i)
            {
               graphicsScene->addLine(winSize.width()/2 - boxSize*(i), 0, winSize.width()/2 - boxSize*(i), winSize.height(), gridPen);
               graphicsScene->addLine(winSize.width()/2 + boxSize*(i), 0, winSize.width()/2 + boxSize*(i), winSize.height(), gridPen);
            }
        }
        

        Should I use the BackgroundDrawer instead?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 23 Mar 2018, 17:34 last edited by mrjj
          #4

          Hi
          Well the grids i have seen uses that. If its more effective than just plain normal drawing
          i never tested but as far as i know, its easier to handle as the rect parameter always
          covers whole view and its design for such use case.

          Regarding endless scrolling. If you dont set a size - the size is the bouncing rect of all items. So in theory one should be able to drag it as far out sa one likes but not sure it will auto expand while dragging so might need some extra code.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mrdebug
            wrote on 23 Mar 2018, 18:21 last edited by
            #5

            I'm using a print report written in Qt (lgpl) where there is a report designer. It is very similar to what you have to do.
            You just have to look at the source code on how to draw, how to manage the mouse events...
            Please have a look
            https://github.com/fralx/LimeReport

            Need programmers to hire?
            www.labcsp.com
            www.denisgottardello.it
            GMT+1
            Skype: mrdebug

            1 Reply Last reply
            1

            1/5

            23 Mar 2018, 17:18

            • Login

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