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. QGraphicsItem And QGraphicsScene
Forum Updated to NodeBB v4.3 + New Features

QGraphicsItem And QGraphicsScene

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 346 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.
  • Ketan__Patel__0011K Offline
    Ketan__Patel__0011K Offline
    Ketan__Patel__0011
    wrote on last edited by
    #1

    Hello Friends And Qt Experts

    I am facing the problem B/W QGraphicsItem And QGraphicsScene

    follow my code
    .h File

    class Custome_Scene : public QGraphicsScene
    {
        Q_OBJECT
    public:
        Custome_Scene(QObject* parent = 0);
        void mouseMoveEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
        void mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
        void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
    }
    

    .cpp File

    Custome_Scene::Custome_Scene(QObject *parent)
    {
    
    }
    void Custome_Scene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
    {
        qDebug() << mouseEvent->scenePos();
    }
    void Custome_Scene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
    {
    
    }
    void Custome_Scene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent)
    {
    
    }
    

    As you see my code
    when i try to get my current position of my mouse from QGraphicsScene
    it will work fine

    but when i Add Any QGraphicsItem in my Custome_Scene that time QGraphicsItem can be Movable or Selectable

    follow my code for Item Add

    Custome_Scene *customescene = new Custome_Scene ();
    QGraphicsRectItem *Item_Rect = new QGraphicsRectItem();
    Item_Rect->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
    Item_Rect->setRect(10,10,100,100);
    Item_Rect->setZValue(1);
    Item_Rect->setVisible(true);
    customescene->addItem(Item_Rect);
    
    JonBJ 1 Reply Last reply
    0
    • Ketan__Patel__0011K Ketan__Patel__0011

      Hello Friends And Qt Experts

      I am facing the problem B/W QGraphicsItem And QGraphicsScene

      follow my code
      .h File

      class Custome_Scene : public QGraphicsScene
      {
          Q_OBJECT
      public:
          Custome_Scene(QObject* parent = 0);
          void mouseMoveEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
          void mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
          void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* mouseEvent) override;
      }
      

      .cpp File

      Custome_Scene::Custome_Scene(QObject *parent)
      {
      
      }
      void Custome_Scene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
      {
          qDebug() << mouseEvent->scenePos();
      }
      void Custome_Scene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
      {
      
      }
      void Custome_Scene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent)
      {
      
      }
      

      As you see my code
      when i try to get my current position of my mouse from QGraphicsScene
      it will work fine

      but when i Add Any QGraphicsItem in my Custome_Scene that time QGraphicsItem can be Movable or Selectable

      follow my code for Item Add

      Custome_Scene *customescene = new Custome_Scene ();
      QGraphicsRectItem *Item_Rect = new QGraphicsRectItem();
      Item_Rect->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
      Item_Rect->setRect(10,10,100,100);
      Item_Rect->setZValue(1);
      Item_Rect->setVisible(true);
      customescene->addItem(Item_Rect);
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Ketan__Patel__0011
      I have tried to understand what you are saying/your problem is but I do not. In principle your code looks fine. So what is the question, can you rephrase it?

      Ketan__Patel__0011K 1 Reply Last reply
      0
      • JonBJ JonB

        @Ketan__Patel__0011
        I have tried to understand what you are saying/your problem is but I do not. In principle your code looks fine. So what is the question, can you rephrase it?

        Ketan__Patel__0011K Offline
        Ketan__Patel__0011K Offline
        Ketan__Patel__0011
        wrote on last edited by
        #3

        @JonB
        Thanks You For Reply

        As You see my code
        i was add RectangleItem in my Custome_Scene

        @Ketan__Patel__0011 said in QGraphicsItem And QGraphicsScene:

        Item_Rect->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);

        Accoranding to this my Item_Rect should be movable or selectable in my Custome_Scene but i can handle it.

        i can't select or move over the my Custome_Scene .

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Ketan__Patel__0011 said in QGraphicsItem And QGraphicsScene:

          mousePressEvent

          Basic c++ - if you override a function and also want the functionality of the base class you should also call the base class implementation of this function.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2

          • Login

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