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. Problem to rotate a QGraphicRectItem

Problem to rotate a QGraphicRectItem

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.2k 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.
  • K Offline
    K Offline
    Kiko007
    wrote on last edited by
    #1

    My problem is when I rotate a rect, this no rotate very well. My centerPoint is (0, 0) corner left-up, but only rotate good when call it twice. I reimplemented mousepressEvent() for to call rotate(90) only.
    Please help me how to rotate properly an Item.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      It would be easier to help you if you provided more information, e.g.

      • post the code that you use
      • explain what you expect to happen
      • explain what you see happening
      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kiko007
        wrote on last edited by
        #3

        Excuse me.

        I want to rotate the rectangle around its point of origin (0, 0) top-left, but when I click the item does not work properly (Figure A). Just after 3 click does what I expected (Figure B). How do I rotate at the first click.

        Another issue is that without the variable num, rotates only once, when I try to make another click does nothing. I have broken my head but I can't get results.

        My Qt version is Qt 5.0.1

        @
        #include <QApplication>
        #include <QtWidgets>
        #include "rectitem1.h"

        int main(int argc, char *argv[])
        {
        QApplication a(argc, argv);

        QGraphicsView *view = new QGraphicsView;
        QGraphicsScene *scene = new QGraphicsScene;
        RectItem1 *item = new RectItem1;
        item->setRect(QRect(0, 0, 100, 200));
        
        scene->addItem(item);
        view->setScene(scene);
        view->resize(600, 600);
        view->show();
        
        return a.exec&#40;&#41;;
        

        }

        #ifndef RECTITEM1_H
        #define RECTITEM1_H

        #include <QGraphicsRectItem>

        class RectItem1 : public QGraphicsRectItem
        {
        public:
        RectItem1();

        protected:
        void mousePressEvent(QGraphicsSceneMouseEvent *event);

        };

        #endif // RECTITEM1_H

        #include "rectitem1.h"

        RectItem1::RectItem1()
        {
        }

        void RectItem1::mousePressEvent(QGraphicsSceneMouseEvent event)
        {
        static int num = 0;
        setRotation(90
        ++num);
        QGraphicsRectItem::mousePressEvent(event);
        }
        @

        "Found Image":http://www.subirimagenes.com/otros-function-8689022.html

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kqt-mr-nv6
          wrote on last edited by
          #4

          I have just compiled your code
          works perfectly

          you have to click inside the rectangular item that you are adding
          otherwise mouse event will not be passed to the RectItem1 object

          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