Results 1 to 10 of 10

Thread: Making Table cell as a combobox?

  1. #1
    Join Date
    Jun 2008
    Posts
    89
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Making Table cell as a combobox?

    Hi,

    I was facing an issue in designing one screen where in I need to display a table and each table cell is a combo and the values in them need to be populated from a Modal view.
    Approach that I had followed is … Creating a QTableView widget and displaying values from a Modal.
    But I am struck – ‘how to make each cell of table as a comb box and the populate each combo with a values from Modal’?

    help me out.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    506
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Making Table cell as a combobox?

    Hi,
    you need to use a custom delegate. In its createEditor()-method, return a new QCombobox.
    Possibly you will need persistend editors in your table, otherwise the combobox will only show up if the users edits the cell.

    Ginsengelf

  3. #3
    Join Date
    Jun 2008
    Posts
    89
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Making Table cell as a combobox?

    i have written my custom delegate but it just works wwith QTableWidget and not with
    QTableView. I need to use QTableView because i want to show data from my Modal.

  4. #4
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    506
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Making Table cell as a combobox?

    That's weird since QTableWidget inherits QTableView...
    Could you show some code?

  5. #5
    Join Date
    Jun 2008
    Posts
    89
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Making Table cell as a combobox?

    That is ok. Got the combobox in table cell using delegate.

    But there is a problem when i use my custom model. My custom model is derived from
    QAbstract item Model...
    When i use this model then only the data is displayed but no combo box is there...
    but when i use QStandardItemModel there is combobox as well as data.

    help!

  6. #6
    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: Making Table cell as a combobox?

    How did you implement flags() and data()? Did you return Qt::ItemIsEditable together with other flags in former and did you handle Qt::EditRole in latter?
    J-P Nurmi

  7. #7
    Join Date
    Jun 2008
    Posts
    89
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Making Table cell as a combobox?

    I have implemented data as

    Qt Code:
    1. QVariant className::data(const QModelIndex & index, int role) const
    2. {
    3. if( index.isValid() == false )
    4. return QVariant();
    5.  
    6. if( role == Qt::EditRole )
    7. {
    8. if( index.internalPointer() )
    9. {
    10. int parentRow = ipToRow(index.internalPointer());
    11. return QString("Cell %3.%1.%2").arg(index.row()).arg(index.column())
    12. .arg(parentRow);
    13. }
    14.  
    15. return QString("Cell %1.%2").arg(index.row()).arg(index.column());
    16. }
    To copy to clipboard, switch view to plain text mode 

    and Flags() as
    Qt Code:
    1. Qt::ItemFlags className::flags( const QModelIndex& idx ) const
    2. {
    3.  
    4. return Qt::ItemIsEditable;
    5. }
    To copy to clipboard, switch view to plain text mode 
    but it did not work.

    did i do something wrong...?

  8. #8
    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: Making Table cell as a combobox?

    Quote Originally Posted by kaushal_gaurav View Post
    Qt Code:
    1. Qt::ItemFlags className::flags( const QModelIndex& idx ) const
    2. {
    3.  
    4. return Qt::ItemIsEditable;
    5. }
    To copy to clipboard, switch view to plain text mode 
    This would mean that all items are disabled, thus non-editable. Try something like:
    Qt Code:
    1. Qt::ItemFlags className::flags(const QModelIndex &index) const
    2. {
    3. if (!index.isValid())
    4. return 0;
    5.  
    6. return Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable;
    7. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  9. #9
    Join Date
    Jun 2008
    Posts
    89
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Making Table cell as a combobox?

    yipeee....it works...
    thanks buddy..

    but how can make it persistent....i have to click the table cell to make it show.

  10. #10
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    506
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Making Table cell as a combobox?


Similar Threads

  1. Replies: 2
    Last Post: 18th March 2008, 15:38
  2. Replies: 4
    Last Post: 4th February 2008, 06:16
  3. Replies: 11
    Last Post: 7th September 2006, 23:15
  4. table with combobox cells
    By mgurbuz in forum Qt Programming
    Replies: 2
    Last Post: 10th May 2006, 12:12
  5. Highlighting the border of cell in Table
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 21st March 2006, 08:20

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.