Results 1 to 7 of 7

Thread: Completer on QItemDelegate

Hybrid View

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

    Default Re: Completer on QItemDelegate

    Actually, now that I give it a try I'm not even able to reproduce the problem. This works just fine for me (with both Qt 4.3.3 and a couple of weeks old snapshot of Qt 4.4):
    Qt Code:
    1. // main.cpp
    2. #include <QtGui>
    3.  
    4. class ItemDelegate : public QItemDelegate
    5. {
    6. public:
    7. ItemDelegate(QObject* parent = 0) : QItemDelegate(parent) { }
    8.  
    9. QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
    10. {
    11. QWidget* editor = QItemDelegate::createEditor(parent, option, index);
    12. QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(editor);
    13. if (lineEdit)
    14. {
    15. QStringList stringList = QStringList() << "foo" << "bar" << "baz";
    16. QCompleter* completer = new QCompleter(stringList, lineEdit);
    17. lineEdit->setCompleter(completer);
    18. }
    19. return editor;
    20. }
    21. };
    22.  
    23. int main(int argc, char* argv[])
    24. {
    25. QApplication app(argc, argv);
    26. QTableWidget table(4, 4);
    27. table.setEditTriggers(QAbstractItemView::AllEditTriggers);
    28. table.setItemDelegate(new ItemDelegate(&table));
    29. table.show();
    30. return app.exec();
    31. }
    To copy to clipboard, switch view to plain text mode 
    Doesn't it work for you?
    J-P Nurmi

  2. #2
    Join Date
    Feb 2008
    Posts
    16
    Thanks
    3

    Default Re: Completer on QItemDelegate

    Quote Originally Posted by jpn View Post
    Actually, now that I give it a try I'm not even able to reproduce the problem. This works just fine for me (with both Qt 4.3.3 and a couple of weeks old snapshot of Qt 4.4):
    Qt Code:
    1. // main.cpp
    2. #include <QtGui>
    3.  
    4. class ItemDelegate : public QItemDelegate
    5. {
    6. public:
    7. ItemDelegate(QObject* parent = 0) : QItemDelegate(parent) { }
    8.  
    9. QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
    10. {
    11. QWidget* editor = QItemDelegate::createEditor(parent, option, index);
    12. QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(editor);
    13. if (lineEdit)
    14. {
    15. QStringList stringList = QStringList() << "foo" << "bar" << "baz";
    16. QCompleter* completer = new QCompleter(stringList, lineEdit);
    17. lineEdit->setCompleter(completer);
    18. }
    19. return editor;
    20. }
    21. };
    22.  
    23. int main(int argc, char* argv[])
    24. {
    25. QApplication app(argc, argv);
    26. QTableWidget table(4, 4);
    27. table.setEditTriggers(QAbstractItemView::AllEditTriggers);
    28. table.setItemDelegate(new ItemDelegate(&table));
    29. table.show();
    30. return app.exec();
    31. }
    To copy to clipboard, switch view to plain text mode 
    Doesn't it work for you?

    When I compile your code as standalone application it works as expected, otherwise when I apply it on my code and on my view, it doesn't work :/ happens exactly the same thing. It is because I don't put AllEditTriggers, but I have only couple of them...try setting the AnyKeyPressed trigger .. doesn't work.

  3. #3
    Join Date
    Feb 2008
    Posts
    16
    Thanks
    3

    Default Re: Completer on QItemDelegate

    Could this be bug in Qt ?

Similar Threads

  1. QItemDelegate Editor Crash
    By mclark in forum Qt Programming
    Replies: 13
    Last Post: 22nd March 2018, 05:06
  2. Return a pointer from a QItemdelegate
    By SailinShoes in forum Qt Programming
    Replies: 5
    Last Post: 12th March 2008, 21:07
  3. QItemDelegate problem
    By WinchellChung in forum Newbie
    Replies: 2
    Last Post: 5th December 2007, 17:16
  4. premature call to setmodeldata with QItemDelegate
    By placebo in forum Qt Programming
    Replies: 1
    Last Post: 25th November 2007, 18:39
  5. Replies: 3
    Last Post: 12th May 2006, 20:31

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
  •  
Qt is a trademark of The Qt Company.