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. Triggering action by click ouside a widget
Forum Updated to NodeBB v4.3 + New Features

Triggering action by click ouside a widget

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 244 Views 2 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.
  • B Offline
    B Offline
    Bert59
    wrote on last edited by
    #1

    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
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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
      2
      • B Offline
        B Offline
        Bert59
        wrote on last edited by
        #3

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

        1 Reply Last reply
        1

        • Login

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