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. Q3DSurface input handler with selection dragging

Q3DSurface input handler with selection dragging

Scheduled Pinned Locked Moved Unsolved General and Desktop
q3dsurfaceq3dinputhandlerpoint selectiondragdata visualizat
1 Posts 1 Posters 931 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.
  • K Offline
    K Offline
    Klay
    wrote on 18 Aug 2016, 16:05 last edited by Klay
    #1

    Hi!

    I'm implementing a custom input handler for Q3DSurface. I'd like to be able to select a point by pressing the left mouse button and drag the selection (change the selected point) according to the current mouse position as long as the button is pressed. When mouse leaves the area of the QSurface3DSeries it would be best to still select a point currently closest to the mouse cursor.

    I managed to make a version where the selection can be dragged (see bellow), however, when the cursor leaves the QSurface3DSeries area I'm only able to set the selected point to the last one. Is there a way to find the closest point easily?

    Also with the current solution when (with a pressed mouse button) I move the cursor away and than comes back into the QSurface3DSeries area the selection dragging is not re-instantiated and I'm left with the point which was the last selected one before leaving the QSurface3DSeries area. (This is because I'm not doing scene()->setSelectionQueryPosition(); the and QAbstract3DGraph::selectedElementChanged is not fired). Any ideas? Thanks!

    class SelectionDrag : public Q3DInputHandler
    {
    private:
        bool m_bLeftButtonPressed;
        Q3DSurface *m_pGraph;
        QPoint m_pLastPoint;
        QSurface3DSeries *m_pSeries;
    public:
        SelectionDrag(Q3DSurface *graph, QObject *parent) :
             Q3DInputHandler(parent),
             m_iSelectedItemType(QAbstract3DGraph::ElementNone),
             m_bLeftButtonPressed(false),
             m_bDragSeriesSelection(false),
             m__LastPosition(0,0),
             m__PrevPosition(0,0),
             m_pGraph(graph),
             m_pLastPoint(0,0),
             m_pSeries(nullptr)
        {
            connect(graph, &QAbstract3DGraph::selectedElementChanged, this,
                    &SelectionDrag::handleElementSelected);
        }
    
        void handleElementSelected(QAbstract3DGraph::ElementType type)
        {
            m_iSelectedItemType = type;
        }
        void mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos)
        {
            if(m_bLeftButtonPressed)
            {
                if(QAbstract3DGraph::ElementSeries == m_iSelectedItemType)
                {
                    scene()->setSelectionQueryPosition(mousePos);
                    m_pSeries = m_pGraph->selectedSeries();
                    m_pLastPoint = m_pSeries->selectedPoint();
                }
                else
                {
                    m_pSeries->setSelectedPoint(m_pLastPoint);
                }
            }
            else
            {
                Q3DInputHandler::mouseMoveEvent(event, mousePos);
                qDebug() << "No Sel";
            }
        }
        void mousePressEvent(QMouseEvent *event, const QPoint &mousePos)
        {
            Q3DInputHandler::mousePressEvent(event, mousePos);
            if (Qt::LeftButton == event->button())
            {
                m_bLeftButtonPressed = true;
            }
        }
    
        void mouseReleaseEvent(QMouseEvent *event, const QPoint &mousePos)
        {
            Q3DInputHandler::mouseReleaseEvent(event, mousePos);
            m_bLeftButtonPressed = false;
        }
    }
    
    1 Reply Last reply
    0

    1/1

    18 Aug 2016, 16:05

    • Login

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