Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6852101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:19:50+00:00 2026-05-27T01:19:50+00:00

When you get get a mouse signal from a model into your slot, the

  • 0

When you get get a mouse signal from a model into your slot, the argument passed is a QModelIndex.

QModelIndex does not tell you what button is pressed. So, we can resort to QApplication::mouseButtons. But QApplication::mouseButtons is the current button press, not when model experienced the click.

My thought experiment is saying that, after the right-button is pressed, the underlying view sends the signal to my widget, but just before my widget’s slot received the signal, a spurious left-click occurred. So calling QApplication::mouseButtons on receipt of QModelIndex would wrongly associate the row being click with the left mouse button rather than the right button. How possible is this scenario?

When you look at Qt and even QML, it takes a lot of code acrobatics to achieve proper mouse button info on receipt of a QModelIndex. Is it a policy that nokia is striving to promote mouse button agnosticism?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:19:50+00:00Added an answer on May 27, 2026 at 1:19 am

    I don’t think this is a very possible scenario but it may happen.

    A “simple” way to be sure about which button was clicked is to subclass QTableView (or the view you are using and reimplement the mouseReleaseEvent.

    void mouseReleaseEvent(QMouseEvent * event)
    {
        // store the button that was clicked
        mButton = event->button();
        // Now call the parent's event
        QTableView::mouseReleaseEvent(event);
    }
    

    By default the mouseReleaseEvent emits the clicked signal if an item of the view is pressed

    If a user presses the mouse inside your widget and then drags the
    mouse to another location before releasing the mouse button, your
    widget receives the release event. The function will emit the
    clicked() signal if an item was being pressed.

    The trick is to catch the clicked signal in your derived class and emit a new signal which except the model index will contain the button as well.

    // Define your new signal in the header
    signals:
        void clicked(QModelIndex, Qt::MouseButton);
    
    // and a slot that will emit it
    private slots:
        void clickedSlot(QModelIndex); 
    
    // In the constructor of your derived class connect the default clicked with a slot 
    connect(this, SIGNAL(clicked(QModelIndex), this, SLOT(clickedSlot(QModelIndex)));
    
    // Now the slot just emits the new clicked signal with the button that was pressed
    void clickedSlot(QModelIndex i)
    {
        emit clicked(i, mButton);
    }
    

    You can do something similar with the mousePressEvent if you need the pressed signal as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how to get the correct mouse position during a drag-and-drop operation
When i don't set background of my panel i can not get mouse events
I want the best way to get mouse position for Form. I,m now set
Is there any way to get mouse position relative to it's parent element? Let's
I get my mouse coordinates like this: winX = QCursor::pos().x(); These are coordinates for
is it possible to get the mouse direction (Left, Right, Up, Down) based on
Is it possible to get the mouse position with JavaScript after page loads without
Is there a way to get the location mouse inside a <canvas> tag? I
How can I get a UIElement to ignore mouse clicks on it and pass
I want to get hold of the mouse position in a timeout callback. As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.