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. How to prevent right mouse clicking to select item in QTableView?
Forum Updated to NodeBB v4.3 + New Features

How to prevent right mouse clicking to select item in QTableView?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 6.8k 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.
  • L Offline
    L Offline
    Landy
    wrote on last edited by
    #1

    Hi guys,

    I am using QTableView in my project, and i implemented a context menu in the QTableView.
    the problem is that: when i clicked right mouse button to pop up context menu, the item in the table will be selected too.
    i don't wanna item is selected when i clicked right mouse button.
    so, is there any swither or something else to do it?

    Thanks.

    -Landy

    1 Reply Last reply
    0
    • B Offline
      B Offline
      b1gsnak3
      wrote on last edited by
      #2

      Subclass QTableView and reimplement mousePressEvent so that when right click event happens you just stop. Something like (might not be all correctly, it's just a sketch):

      @
      void MyClass::mousePressEvent(QMouseEvent *e) {
      if(e->button() == Qt::RightMouseButton) {
      return;
      } else {
      QTableView::mousePressEvent(e);
      }
      }
      @

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vittalonline
        wrote on last edited by
        #3
            view->setSelectionBehavior(QAbstractItemView::SelectRows);
            view->setSelectionMode(QAbstractItemView::SingleSelection);
        
        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