Results 1 to 20 of 21

Thread: How does the QItemDelegate work?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default How does the QItemDelegate work?

    Hello,

    I have followed the example of creating a spinboxdelegate in a QTableWidget.
    http://doc.trolltech.com/4.3/itemvie...xdelegate.html

    I have subclassed the QTableWidget in order to specify the return as hotkey for both open(F2) and close(return) the spinbox delegate. To do that I have overrided the keyPressEvent. This is the example code of the KeyPressEvent:

    Qt Code:
    1. void MyTableWidget::keyPressEvent(QKeyEvent *e)
    2. {
    3.  
    4.  
    5. if(e->key() == Qt::Key_Return)
    6. {
    7.  
    8. n = new QKeyEvent(e->type(), Qt::Key_F2, e->modifiers(), e->text(), e->isAutoRepeat(), e->count());
    9.  
    10. }
    11. else
    12. {
    13.  
    14. n = e;
    15.  
    16. }
    17.  
    18. QTableWidget::keyPressEvent(n);
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 
    I use:
    tableWidget->setItemDelegateForColumn(1, new SpinBoxDelegate);

    instead of the example codes:
    SpinBoxDelegate delegate;
    tableView.setItemDelegate(&delegate);

    When I crosscompile & and transfer the example code to an embedded system (Arm9, QTopia 4.3) the spinbox delegate and its methods createEditor and setEditorData is never called when the cell is opened for editing?

    I really need this to work. I have no idea why the spinbox delegate does not work on the embedded system? If you need further info to be able to help I will provide it for you.

    Thank you in advance...
    Last edited by jpn; 2nd March 2008 at 09:28. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How does the QItemDelegate work?

    Why do you override the key event like that? How about handling the key by calling QAbstractItemView::edit() on the cell you want to edit? Just make sure your key handler is called at all.

  3. #3
    Join Date
    Mar 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How does the QItemDelegate work?

    Hi wysota,

    I dont know if i follow you...do you mean something like this?

    Qt Code:
    1. void MyTableWidget::keyPressEvent(QKeyEvent *e)
    2. {
    3.  
    4.  
    5. if(e->key() == Qt::Key_Return)
    6. {
    7.  
    8. QAbstractItemView::edit(currentIndex())
    9.  
    10. }
    11.  
    12. QTableWidget::keyPressEvent(n);
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 2nd March 2008 at 10:48. Reason: missing [code] tags

  4. #4
    Join Date
    Mar 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How does the QItemDelegate work?

    Sorry the previous dont work...I mean like this:

    Qt Code:
    1. void MyTableWidget::keyPressEvent(QKeyEvent *e)
    2. {
    3.  
    4. QAbstractItemView::edit(currentIndex(), QAbstractItemView::EditKeyPressed, e);
    5. QTableWidget::keyPressEvent(e);
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 2nd March 2008 at 10:47. Reason: missing [code] tags

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How does the QItemDelegate work?

    Using QShortcut is also an option. If you want to edit with any key you might want to take a look at QAbstractItemView::editTriggers.
    J-P Nurmi

  6. #6
    Join Date
    Mar 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How does the QItemDelegate work?

    Hello again,

    These solutions you have proposed works just fine on my laptop...but neither one of them make it possible to use the spinbox delegate on the arm9 and QTopia? It just opens the cell for editing and there is no contact with the spinbox delegate?

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How does the QItemDelegate work?

    So, there's a QLineEdit editor or what? Could you assure that SpinBoxDelegate::createEditor() gets called?
    J-P Nurmi

  8. #8
    Join Date
    Mar 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How does the QItemDelegate work?

    So, there's a QLineEdit editor or what?

    How do you mean? I think there is yes?

    Could you assure that SpinBoxDelegate::createEditor() gets called?

    On my laptop yes. The SpinBoxDelegate::createEditor() is called on my laptop...I can set a toggle break point in it and debug it when called...

    But It never stops at the break point when debugging on the arm9? I also have qDebug output traces in each SpinBoxDelegate method but none is called on the arm9?

    Im somewhat confused and cannot understand why? Could it be some limitation in QTopia? Differencies in the plattforms?

  9. #9
    Join Date
    Mar 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How does the QItemDelegate work?

    wysota I qoute you:

    "You are allocating the delegate on the stack and it gets out of scope immediately after you return from the method that sets the delegate and the delegate gets destroyed and a default delegate takes its place."

    This sounds very reasonable, it could be. I will look into this tomorrow monday. I was just passing my job to check my mails, but was stuck on this problem I have had for a while.

  10. #10
    Join Date
    Mar 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How does the QItemDelegate work?

    If I can override the F2 (open edit) another hotkey using:

    QAbstractItemView::edit(currentIndex(), QAbstractItemView::EditKeyPressed, e);

    How do I override the up & down buttonwhen in edit mode?

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How does the QItemDelegate work?

    Reimplement the key event handler for your editor returned by the delegate or install an event filter on the editor and handle those keys in the filter.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How does the QItemDelegate work?

    You are allocating the delegate on the stack and it gets out of scope immediately after you return from the method that sets the delegate and the delegate gets destroyed and a default delegate takes its place.

Similar Threads

  1. QItemDelegate Editor Crash
    By mclark in forum Qt Programming
    Replies: 13
    Last Post: 22nd March 2018, 04:06
  2. premature call to setmodeldata with QItemDelegate
    By placebo in forum Qt Programming
    Replies: 1
    Last Post: 25th November 2007, 17:39
  3. QActions don't work with menubar hidden
    By Pepe in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2007, 01:04
  4. Change work area OS
    By pakulo in forum Qt Programming
    Replies: 15
    Last Post: 15th May 2007, 07:20
  5. QTextEdit Justify align making work
    By dec0ding in forum Qt Programming
    Replies: 2
    Last Post: 13th January 2006, 12:02

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.