Results 1 to 8 of 8

Thread: QCombobox as QTableView delegate

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2007
    Posts
    11
    Thanks
    3
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default QCombobox as QTableView delegate

    Hello all,

    I would like to display a QComboBox in my QTableView.
    I have tried to use the QItemDelegate, but it only shows it when I editing the cell.
    Now I am using the QStyledItemDelegate in the following way:

    Qt Code:
    1. void FuseDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3. painter->save();
    4. switch(index.model()->data(index, Qt::UserRole).toInt()) {
    5. case FuseBitField_boolean: {
    6. QCheckBox *editor = new QCheckBox();
    7. editor->setGeometry(option.rect);
    8. editor->render(painter);
    9. } break;
    10. case FuseBitField_enum: {
    11. QComboBox *editor = new QComboBox();
    12. editor->setGeometry(option.rect);
    13. editor->render(painter);
    14. } break;
    15. default:
    16. return QStyledItemDelegate::paint(painter, option, index);
    17. }
    18. painter->restore();
    19. }
    To copy to clipboard, switch view to plain text mode 

    But it does not displays anything. Editing works fine.

    Is it possible to show a a widget with a delegate in non editing mode, or I should base my design on QTableWidget, and use addCellWidget()?

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

    frankiefrank (25th July 2011)

Similar Threads

  1. Replies: 2
    Last Post: 29th December 2012, 14:14
  2. QTableView doesn't use delegate
    By treaves in forum Qt Programming
    Replies: 3
    Last Post: 1st February 2010, 09:45
  3. QTableView in ui with model/delegate
    By tpf80 in forum Qt Programming
    Replies: 7
    Last Post: 6th November 2008, 23:00
  4. QTableView Delegate Usage
    By rajeshs in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2008, 07:03
  5. Again QTableWidget and QComboBox delegate
    By Aki-Matti in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2008, 13:40

Tags for this Thread

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.