Results 1 to 3 of 3

Thread: table with combobox cells

  1. #1
    Join Date
    Apr 2006
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default table with combobox cells

    Is there anyway to create a table includes combobox cells in Qt 4.1.1 version?
    I followed the "delegatespinbox" example to add combobox but wasn't successful.

    delegate.cpp

    delegate.h

    main.cpp

    Thank you for any help

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

    Default Re: table with combobox cells

    There is some extra parameter "int col" in DelegateSpinBox::createEditor(), and that's why createEditor() never gets called.

    virtual QWidget* QItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const

    Just to get the concept right:
    - createEditor() is supposed to create and initialize the editor for the given index. Add combo items, set spin ranges, etc here.
    - setEditorData() is supposed to set correct content to the editor when the editing mode starts, you don't need to initialize and/or set editor properties anymore.
    - setModelData() is supposed to exchange the data from the editor to the model when the editing mode ends, you don't need to initialize and/or set editor properties here either. (Oh, and btw check DelegateSpinBox::setModelData(), in "index.column() == 3", 3 should be 2).
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    mgurbuz (10th May 2006)

  4. #3
    Join Date
    Apr 2006
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: table with combobox cells

    Thank you for your help.
    It works just fine...


    Quote Originally Posted by jpn
    There is some extra parameter "int col" in DelegateSpinBox::createEditor(), and that's why createEditor() never gets called.

    virtual QWidget* QItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const

    Just to get the concept right:
    - createEditor() is supposed to create and initialize the editor for the given index. Add combo items, set spin ranges, etc here.
    - setEditorData() is supposed to set correct content to the editor when the editing mode starts, you don't need to initialize and/or set editor properties anymore.
    - setModelData() is supposed to exchange the data from the editor to the model when the editing mode ends, you don't need to initialize and/or set editor properties here either. (Oh, and btw check DelegateSpinBox::setModelData(), in "index.column() == 3", 3 should be 2).

Similar Threads

  1. Postgresql QSqlRelationalTableModel empty table
    By RolandHughes in forum Qt Programming
    Replies: 0
    Last Post: 12th November 2008, 17:18
  2. Making Table cell as a combobox?
    By kaushal_gaurav in forum Qt Programming
    Replies: 9
    Last Post: 1st August 2008, 12:04
  3. selected cells' table
    By dreamer in forum Qt Programming
    Replies: 5
    Last Post: 19th June 2008, 08:59
  4. Table and validating cells
    By zorro68 in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2007, 23:22
  5. Filling combobox from database
    By Philip_Anselmo in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2006, 17:53

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.