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

QGraphicsScene and mouseEvent

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

    Good afternoon. There is a tied QGraphicsScene to QGraphicsView. I overloaded the mouse event, for drawing on the stage. But I do not understand how to return a pointer to the selected drawn object. By default, double-clicking the mouse highlights the object, I set the flag: line-> setFlag (QGraphicsItem :: ItemIsSelectable).
    Object: QGraphicsLineItem * line = new QGraphicsLineItem .
    Help to return the pointer to the selected object, to change it and view the coordinates of the line (beginning and end).

    S 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Did you already took a look at the Graphics View Examples ? You might find there several source of inspiration for your application.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L lenina15i25

        Good afternoon. There is a tied QGraphicsScene to QGraphicsView. I overloaded the mouse event, for drawing on the stage. But I do not understand how to return a pointer to the selected drawn object. By default, double-clicking the mouse highlights the object, I set the flag: line-> setFlag (QGraphicsItem :: ItemIsSelectable).
        Object: QGraphicsLineItem * line = new QGraphicsLineItem .
        Help to return the pointer to the selected object, to change it and view the coordinates of the line (beginning and end).

        S Offline
        S Offline
        samdol
        wrote on last edited by samdol
        #3

        @lenina15i25
        Have you looked at
        http://doc.qt.io/qt-5/qtwidgets-graphicsview-diagramscene-example.html
        I also tried to get the pointer of drawn object on scene by passing pointer. Strange, but I could not get it.
        In the example,

        bool DiagramScene::isItemChange(int type)
        {
            foreach (QGraphicsItem *item, selectedItems()) {
                if (item->type() == type)
                    return true;
            }
            return false;
        }
        

        It might be the function you need.
        Then you try something like

        void DiagramScene::setLineColor(const QColor &color)
        {
            myLineColor = color;
            if (isItemChange(Arrow::Type)) {
                Arrow *item = qgraphicsitem_cast<Arrow *>(selectedItems().first());
                item->setColor(myLineColor);
                update();
            }
        }
        

        to get the pointer of selected item and do something on it.

        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