Results 1 to 2 of 2

Thread: default QTableView behavior question

  1. #1
    Join Date
    Apr 2016
    Posts
    32
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products

    Default default QTableView behavior question

    I have a tableview with a column that has selection and editing disabled. When I click on a row in that column and press a key, it jumps to the next row that starts with the key that I pressed. I can't find anything in the documentation about this behavior. Is it possible to turn it off?

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: default QTableView behavior question

    Quote Originally Posted by nlgootee View Post
    Is it possible to turn it off?
    First, I believe this behavior is pretty standard, or at least in my experience, I would expect a view to work exactly as you described. If, however, you do want to change that behavior, I believe you are going to have to override the virtual function named keyPressEvent for QTableView. I'm not sure if you already have a QTableView subclass or not, but much like your ManifestModel subclass of QSqlTableModel, I believe you'll have to do the same for QTableView.

    By default, the event object you will receive is already marked as "accepted". If you simply return, they key press won't be passed to any other event filters, effectively eating it.

    If you wish to take no action on *any* key presses for your QTableView, then you should create a subclass of a QTableView and implement a method named keyPressEvent similar to the code below:

    Qt Code:
    1. def keyPressEvent(self, event):
    2. return
    To copy to clipboard, switch view to plain text mode 

    You can alternatively inspect the event object itself to figure out which key was actually pressed and selectively determine whether or not you want to "accept" the keypress. If you want no action to be taken, simply return, or invoke QTableView.keyPressEvent(event) for the default behavior for that key press.

    There may be other ways to accomplish this, for example I believe you could install an event filter on your QTableView instance without having to subclass it, but effectively you need to get access to the event and either accept ("eat" it) or invoke the base class's event to achieve the default behavior.

    Good luck.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. Question about behavior of QGraphicsView/QGraphicsScene
    By kennethadammiller in forum Newbie
    Replies: 0
    Last Post: 22nd July 2010, 09:56
  2. Tab behavior versus Arrow in QTableView
    By klahey in forum Qt Programming
    Replies: 1
    Last Post: 20th January 2010, 13:58
  3. the question about define my own selection behavior
    By calmspeaker in forum Qt Programming
    Replies: 1
    Last Post: 20th June 2009, 11:40
  4. Pre app.exec() behavior question
    By sgmurphy19 in forum Qt Programming
    Replies: 3
    Last Post: 15th September 2008, 22:02
  5. disabling a default Alt-key behavior
    By roxton in forum Qt Programming
    Replies: 0
    Last Post: 4th June 2008, 16:15

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.