Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved Triggering action by click ouside a widget

    General and Desktop
    2
    3
    69
    Loading More Posts
    • 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.
    • B
      Bert59 last edited by

      I have th following layout
      bf791e2d-9d14-44b8-b3ed-0278d23da3e5-image.png

      When I click on a plot it is displayed with a thicker line to visualize that it is selected. I can then delete it with the delete button.
      For each serie I add to the chart I create a connection to a slot which increases the thickness of the plot.
      connect(serie, &QLineSeries::clicked, this, &AtollMain::handleClickedPlot);

      After a plot has been selected I would like to unselect it when I click anywhere of the Graph or outside the GraphicsView.

      I tried to reimplement the mousePressEvent for the QGraphicsView for unselecting plots, but then when I click on a plot the connection previously setup doesn't work and I cannot select a plot.

      How could I achieve what I'm looking for?

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by mrjj

        Hi
        When you override the mouse press, you must still call
        the base class mouse press - as else some feature might break.

        If you know if you have something selected, then you could use
        something like

        void QGraphicsView::mousePressEvent(QMouseEvent *e) {
        if (somethingSelected)
          deselect(); // however, it must happen
        else
          QGraphicsView::mousePressEvent(e); // call base class so it can still select stuff
        }
        
        1 Reply Last reply Reply Quote 2
        • B
          Bert59 last edited by

          Thank you very munch.
          As a beginner with Qt I always forget that you have to forward the unhandled events.

          1 Reply Last reply Reply Quote 1
          • First post
            Last post