Results 1 to 1 of 1

Thread: Changing tab key functionallity in QItemDelegate

  1. #1
    Join Date
    May 2009
    Location
    Copenhagen
    Posts
    50
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Changing tab key functionallity in QItemDelegate

    Hi,
    I'm using a QTreeView and I want to change the tab functionallity so it moves focus to the next column of the treeview instead of that of the one below (same behavior as QTableView ). The problem arises when the widget, created by the QItemDelegate, is in editing mode. In the tableview, the focus will move right and bring the next index in focus - so the user can start typing right away, which is great functionallity. In the treeview however, the focus moves down and sets the index below in focus. I want the treeview to behave like the tableview and move focus right (not down).

    I'm trying to solve this by subclassing the QItemDelegate and implement a special editorEvent function, like this...

    Qt Code:
    1. bool ItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
    2. {
    3. if (event->type() == QEvent::KeyPress)
    4. if (static_cast<QKeyEvent*>(event)->key() == Qt::Key_Tab)
    5. qDebug() << "Tab was pressed";
    6.  
    7. return QItemDelegate::editorEvent( event , model , option , index ) ;
    8. }
    To copy to clipboard, switch view to plain text mode 

    The event doesn't seem to catch the Tab keypress. It's like the keypress handler is NOT moved to the widget created by the QItemDelegate. I tried to solve this by installing the eventfilter on the widget created by the delegate..

    Qt Code:
    1. QWidget * ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index)
    2.  
    3. QWidget *w = QItemDelegate::createEditor(parent,option,index) ;
    4. w->installEventFilter( const_cast< ItemDelegate * >(this) );
    5. return w;
    6. }
    To copy to clipboard, switch view to plain text mode 

    What am I doing wrong??

  2. The following user says thank you to Nightfox for this useful post:


Similar Threads

  1. QSlider: changing the groove without changing the handle
    By Olivier Berten in forum Qt Programming
    Replies: 3
    Last Post: 30th April 2013, 11:02
  2. Replies: 2
    Last Post: 10th August 2009, 10:45
  3. QItemDelegate
    By Alex_123 in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2008, 12:40
  4. Using most of QItemDelegate
    By joshuajcarson in forum Qt Programming
    Replies: 4
    Last Post: 6th October 2008, 17:02
  5. QItemDelegate
    By cyberboy in forum Qt Programming
    Replies: 10
    Last Post: 27th June 2008, 18:41

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.