Results 1 to 2 of 2

Thread: how to customize edit key in QTableView?

  1. #1
    Join Date
    Jun 2012
    Posts
    7
    Thanks
    2

    Default how to customize edit key in QTableView?

    Hi, everyone.
    How to customize a edit key in QTableView?

    I use a customized delegate to edit data in model. The cell editor can be triggered by a way defined by setEditTriggers ( EditTriggers ).
    But I don't find a way to define custom key, such an enter or some other key. There are only 7 trigger types, but no one is what I need.

    Thank you.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to customize edit key in QTableView?

    Use a QShortcut, connect the activated() signal to a slot, and call the view's edit() slot. Something like:
    Qt Code:
    1. class Table: public QTableView
    2. {
    3. Q_OBJECT
    4. public:
    5. Table(QWidget *p = 0): QTableView(p) {
    6. QShortcut *s = new QShortcut(QKeySequence(tr("Ctrl+;")), this);
    7. connect(s, SIGNAL(activated()), SLOT(editActivated()));
    8. }
    9. private slots:
    10. void editActivated() {
    11. edit(currentIndex());
    12. }
    13. };
    To copy to clipboard, switch view to plain text mode 

    If you intercept Enter to start and edit you may lose it as a way to end the edit as it is by default.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  3. The following user says thank you to ChrisW67 for this useful post:

    apango (7th April 2013)

Similar Threads

  1. QTableView line edit clears the text on edit
    By PlasticJesus in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2015, 19:06
  2. Can't edit my QTableView cells
    By MattPhillips in forum Newbie
    Replies: 4
    Last Post: 2nd February 2011, 13:49
  3. QTableView Edit Focus
    By waynew in forum Qt Programming
    Replies: 2
    Last Post: 16th August 2010, 12:24
  4. customize QTableView to add blank rows
    By rosenth in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2010, 11:47
  5. Replies: 1
    Last Post: 9th August 2009, 15:27

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.