Results 1 to 8 of 8

Thread: Adding an editor to the already existing list of QItemEditorFactory

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding an editor to the already existing list of QItemEditorFactory

    thats a very good catch! but i dont know how you are able to edit both data types when commenting setDefaultFactory()...anyways, couple of ways to resolve your issue:

    1. using delegate: dont set this factory as default, just call setItemEditorFactory(QItemEditorFactory *) on QStyledItemDelegate, Qt's right hand for drawing views. thus when QVariant::Type is Color, it will create your custom editor, for all other QVariant types, it will use default factory.

    2. derive from QItemEditorFactory, implement createEditor(..) in a way that if type is Color, it will use ColorEditor, otherwise it will call default factory's createEditor(..). next, set this new class as the default editor factory.

    i think second one will work better for you, i.e. without interfering with any delegate.

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

    schall_l (25th May 2009)

  3. #2
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Adding an editor to the already existing list of QItemEditorFactory

    Thank you talk2amulya, the second one did effectively worked for me.

    Here is the code if someone is interested in:

    Qt Code:
    1. class IdentifiersEditor : public QItemEditorFactory
    2. {
    3. public:
    4. inline IdentifiersEditor() {}
    5. QWidget *createEditor(QVariant::Type type, QWidget *parent) const;
    6. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. IdentifiersEditor::createEditor(QVariant::Type type, QWidget *parent) const {
    2. switch (type) {
    3. case QVariant::Color: {
    4. ColorListEditor *cb = new ColorListEditor(parent);
    5. cb->setFrame(false);
    6. return cb;
    7. }
    8. default:
    9. return QItemEditorFactory::createEditor(type, parent);
    10. break;
    11. }
    12. return 0;
    13. }
    To copy to clipboard, switch view to plain text mode 

  4. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding an editor to the already existing list of QItemEditorFactory

    I have a doubt. You will still need to set your factory somewhere right ?
    Also in the example in post #1, you create a QItemEditorFactory and thats why you dont get the default editors with it.

    Why cant you obtain the factory from item delegate and register you editor ??
    QItemDelegate::itemEditorFactory and QStyledItemDelegate::itemEditorFactory

    Wont it be easier ?

Similar Threads

  1. Adding items to a QGraphicsScene's selection list?
    By mooreaa in forum Qt Programming
    Replies: 2
    Last Post: 1st July 2008, 20:01

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.