Results 1 to 3 of 3

Thread: QItemDelegate and custom widget

  1. #1
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question QItemDelegate and custom widget

    hi, i subclassed QWidget as CustomWidget, and in CustomDelegate:: createEditor() i new a CustomWidget instance and return it. now once i double click the item in a view, the editor widget was created, and once i press the editor widget( a CustomWidget instance), the delegate commit data and close editor and the editor widget was destroyed. this is not our expection. i wonder how to control the editor widget's closing event, for example, click event will edit the data, and double click event will close the editor and commit data.

    i'v read the star delegate in Qt's example, however, in the following code, i cannot change the close event from "release" to "double click".

    in this example, once the mouse release, the editor was destroyed.

    Qt Code:
    1. void StarEditor::mouseReleaseEvent(QMouseEvent * /* event */)
    2. {
    3. emit editingFinished();
    4. }
    5. //! [3]
    6. void StarEditor::mouseDoubleClickEvent(QMouseEvent *event)
    7. {
    8. emit editingFinished();
    9. }
    10. void StarEditor::mousePressEvent(QMouseEvent *event)
    11. {
    12. update();
    13. }
    To copy to clipboard, switch view to plain text mode 

    Thanks!

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

    Default Re: QItemDelegate and custom widget

    Did you reimplement any event handler? Can you show us the code?

  3. #3
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: QItemDelegate and custom widget

    Quote Originally Posted by wysota View Post
    Did you reimplement any event handler? Can you show us the code?
    neither
    Qt Code:
    1. bool StarWidget::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. if (obj == label)
    4. {
    5. if(event->type() == QEvent::MouseButtonPress)
    6. {
    7. setChecked(!checked);
    8. return true;
    9. }
    10. else if(event->type() == QEvent::MouseButtonDblClick)
    11. {
    12. emit editingFinished();
    13. return true;
    14. }
    15. else if (event->type() == QEvent::MouseButtonRelease)
    16. {
    17. return true;
    18. }
    19. }
    20. else
    21. return true;//QObject::eventFilter(obj, event);
    22. }
    To copy to clipboard, switch view to plain text mode 

    nor
    Qt Code:
    1. void StarWidget::mouseDoubleClickEvent(QMouseEvent* /*event*/)
    2. {
    3. // emit editingFinished();
    4. }
    5.  
    6. void StarWidget::mousePressEvent(QMouseEvent * /*event*/)
    7. {
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    is working. so i don't know how to prevent the delegate close the editor when pressing the item.

Similar Threads

  1. Possible to use a widget in another widget's paintEvent?
    By robot_love in forum Qt Programming
    Replies: 2
    Last Post: 9th September 2008, 05:18

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.