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. [SOLVED] mousePressEvent called only from certain areas in scene
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] mousePressEvent called only from certain areas in scene

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.7k 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.
  • I Offline
    I Offline
    IBalic
    wrote on last edited by
    #1

    EDIT: Almost solved, see first reply!

    I have an application which draws lines based on different data from cars. I want my application to be able to select the lines drawn, and then make the corresponding item selected in a list on the left as well. The problem is that the mousePressEvent is only called when I press the mousebutton in the rightmost quarter of the scene. When it is called the curveSelected() function works as well, but I can't figure out why I can't invoke the mousePressEvent from the other areas on the scene.

    First of all I have a mousePressEvent.
    @
    void DrawingScene::mousePressEvent ( QGraphicsSceneMouseEvent * event ){
    event->ignore();
    bool leftbutton = (event->button() == Qt::LeftButton);
    if(leftbutton)
    {
    qDebug() << "leftbutton";
    emit leftButtonPress(event->scenePos());
    }
    QGraphicsScene::mousePressEvent(event);
    }
    @
    Later connected:
    @
    connect(d_scene, SIGNAL(leftButtonPress(QPointF)), this, SLOT(curveSelected(QPointF)));
    @

    leftButtonPress is the signal emitted. Then I have the function which selects the item in the list. This method seems to work just fine. The problem exists without this function as well.

    @
    void CurveDrawer::curveSelected(QPointF pos){
    QMapIterator<QPair<unitID, QString>, carData*> it(dataMap);
    while(it.hasNext()){
    it.next();
    QPainterPath curPath = it.value()->pathItem->path();
    if(curPath.contains(pos)){
    for (int i = 0; i < list->count(); ++i) {
    QListWidgetItem* curItem = list->item(i);
    if(curItem == it.value()->listItem){
    qDebug() << "curveSelected";
    curItem->setSelected(true);
    }
    }
    }
    }
    }
    @

    Anyone experienced something similar, or may see some obvious mistakes in my code?

    How can i achieve that the mousePressEvent is called every time I click inside the scene? This is basically what I want it to do. Now it is only called when I click in a certain area.

    Noticed that this guy had some similar problem: http://www.qtcentre.org/threads/37031-GraphicsView-mousePressEvent-problem--

    EDIT: I tried to implement it with void DrawGraphicsView;;mousePressEvent(QMouseEvent *event) now, and the same problem existed there. The event just got invoked from certain areas in the scene.

    EDIT2: The strange thing for me is that when a certain place in the scene is in the left of the viewport it is not possible to invoke the mousepressEvent, but when I scroll the same place to the right in the viewport, then it is suddenly possible to invoke the mousepressEvent. Does this make the problem clearer?

    1 Reply Last reply
    0
    • I Offline
      I Offline
      IBalic
      wrote on last edited by
      #2

      This was my first post here so just tell me if my approach to describe the problem was wrong in some way :)

      Anyway, I managed to solve the problem in some way. In my my scene, I have to sliders, one vertical and one horizontal. They are placed in the top left corner. If you draw an "invisible" line from the end of both sliders, they form a rectangle explicitly not shown. This area was the area I couldn't receive mousePressEvents from. My quickfix was to make the sliders smaller and then have almost the whole scene as a place where I could get events from.

      But how could I still have these sliders big and still receive events from the same area (preferably the whole area)?

      The sliders are placed in a gridlayout to make them appear in the topleft corner and I have then placed the layout in a widget with the graphicsview as its parent.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mkuettler
        wrote on last edited by
        #3

        [quote author="IBalic" date="1342101652"]The sliders are placed in a gridlayout to make them appear in the topleft corner and I have then placed the layout in a widget with the graphicsview as its parent.[/quote]

        I don't quite understand how you did that, but that sounds like that widget is your problem. Could it be that the widget that holds the sliders partly covers your graphicsview, but is invisible? Then it would of course get the click events; and that would explain why the area is smaller when the sliders are smaller.

        I'm not sure where you want to put these sliders, but "in a widget with the graphicsview as its parent" does not sound like a good solution. I think the only children of the graphicsview should be the viewport, the scrollbars, and maybe the corner widget.

        1 Reply Last reply
        0
        • I Offline
          I Offline
          IBalic
          wrote on last edited by
          #4

          Yeah, you are right. I placed the widget outside the graphicsview, and that solved the problem. Thank you!

          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