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. Refering to other coordinate systems QGraphicsItems
Forum Updated to NodeBB v4.3 + New Features

Refering to other coordinate systems QGraphicsItems

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 634 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.
  • S Offline
    S Offline
    Suprabas
    wrote on last edited by
    #1

    Hello everyone

    I'm learning Qt Creator atm and I encountered a problem I can't really solve on my own. I am building a board game with a GUI with figures and the board field overall and where u can see all movements that were made. Now my problem is that im using QGraphicScene and my own QGraphicItem which is inheriting from QGraphicEllipseItem (these I use for my figures) and if I want to move the figures around but the reference is always to the local coordinate system for example if I'm doing:

    figur.setPos(QPoint p) or figur.moveBy(QPoint p)

    the (0,0) is always in the center of my figure.But I want it to be at the top left of the scene for example. Because of that my boardfield is different for every figure for each figur it always uses their local coordinate system ,so i can't define my boardfields for everyone. I tried mapping and transforming but wasnt too succesful. I just wanna access the scene coordinate system. Thanks for reading and sorry for my bad english I hope my problem was understandable.

    raven-worxR 1 Reply Last reply
    0
    • S Suprabas

      Hello everyone

      I'm learning Qt Creator atm and I encountered a problem I can't really solve on my own. I am building a board game with a GUI with figures and the board field overall and where u can see all movements that were made. Now my problem is that im using QGraphicScene and my own QGraphicItem which is inheriting from QGraphicEllipseItem (these I use for my figures) and if I want to move the figures around but the reference is always to the local coordinate system for example if I'm doing:

      figur.setPos(QPoint p) or figur.moveBy(QPoint p)

      the (0,0) is always in the center of my figure.But I want it to be at the top left of the scene for example. Because of that my boardfield is different for every figure for each figur it always uses their local coordinate system ,so i can't define my boardfields for everyone. I tried mapping and transforming but wasnt too succesful. I just wanna access the scene coordinate system. Thanks for reading and sorry for my bad english I hope my problem was understandable.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @Suprabas
      how do you create (the ellipse) your QGraphicEllipseItem?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Suprabas
        wrote on last edited by Suprabas
        #3

        I use scene->addItem(QGraphicsItem *item)

        *edit: I also use the new operator and set the rect and the pen of course

        raven-worxR 1 Reply Last reply
        0
        • S Suprabas

          I use scene->addItem(QGraphicsItem *item)

          *edit: I also use the new operator and set the rect and the pen of course

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @Suprabas
          please show the code where you set the rect (and its values)

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Suprabas
            wrote on last edited by Suprabas
            #5

            So im making a game that uses 4 figures for each player each player has a different color and the numbers of players can change from 2-4 players(The game is a simple version of Ludo).I'm using two own classes first the matchfield class where I wanna save the positions from each field(a matchfield has around 40 fields where the figures move through similiar to a Ludo gamefield) like I did here my houseFields(here matchfield.H) where the figures start etc.
            So my housefields are declared to the correct coordinate system here it works all fine.The first code below works correctly. The second one where I use ellipse.setPos(qreal ax,qreal ay) doesn't. It uses the coordinate system of the item and i don't want that I still wanna use the scene coordinate system.`So I can use only set my boardgame positions in my matchfield class and use it from every figur position.

            And just for undestanding I'm using an array of *figures ellipse[16] (because 16 is the max amount of figures with 4 players)``

            // First code
            for(int playerCount=0;playerCount<player*4;playerCount++){
                    matchfield.ellipse[playerCount]=new figures();
                    matchfield.ellipse[playerCount]->nr=playerCount;
                    matchfield.ellipse[playerCount]->setPen(pen);
                    matchfield.ellipse[playerCount]->setRect(matchfield.H[playerCount].x(),matchfield.H[playerCount].y(),26,26);
                    if(playerCount<=4){
                        brush.setColor(Qt::darkYellow);}
                    if(playerCount>=4){
                        brush.setColor(Qt::darkGreen);}
                    if(playerCount>=8){
                        brush.setColor(Qt::blue);}
                    if(playerCount>=12){
                        brush.setColor(Qt::red);}
                    matchfield.ellipse[playerCount]->setBrush(brush);
                    scene->addItem(matchfield.ellipse[playerCount]);
                };
            //Second code. Here is an example where i wanna use the scene coordinate system and not the local coordinate system from the QGraphicsitem
            
            void MainWindow::on_pushButton_2_clicked()
            {
                int i=ui->doubleSpinBox->value();
                matchfield.ellipse[i-1]->setPos(0,200);
            }
            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