Results 1 to 2 of 2

Thread: QSortFilterProxyModel with QComboBox

  1. #1
    Join Date
    Aug 2008
    Posts
    60
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QSortFilterProxyModel with QComboBox

    Hi,
    Can you please let me know how to use QSortFilterProxyModel with QComboBox, for hiding or showing any item in combobox.
    Thank you in advance.

  2. #2
    Join Date
    Aug 2006
    Location
    Zürich, Switzerland
    Posts
    23
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSortFilterProxyModel with QComboBox

    There's no direct relation between QComboBox and QSortFilterProxyModel.
    QComboBox can serve as an item delegate in an item view (QTreeView, QTableView) to give the user a choice for data entry.

    You will find more about item delegates in the Qt documentation.

    Just to give an idea how it works. If the item delegate (in thie example a class with name "IemDelegate") is registered with a view the "createEditor" method is called from the view when needed to give user the option to enter a value from the combo box:

    Qt Code:
    1. QWidget* ItemDelegate::createEditor(QWidget* parent,
    2. const QStyleOptionViewItem& option,
    3. const QModelIndex& index) const
    4. {
    5. QComboBox* editor = new QComboBox(parent);
    6.  
    7. editor->addItem("Entry 1");
    8. editor->addItem("Entry 2");
    9. editor->addItem("Entry 3");
    10.  
    11. return editor;
    12. }
    To copy to clipboard, switch view to plain text mode 

    Since the "createEditor" method gets the QModelIndex for the data to be edited you can access the related model if really necessary:

    Qt Code:
    1. index.model();
    To copy to clipboard, switch view to plain text mode 

    If your view has a QSortFilterProxyModel attached then the model returned above is exactly this.

    Regards
    Ernst

Similar Threads

  1. QItemDelegate, QDataWidgetMapper and QComboBox
    By cydside in forum Qt Programming
    Replies: 7
    Last Post: 8th April 2009, 18:44
  2. QComboBox - Few virtual methods
    By gruszczy in forum Qt Programming
    Replies: 17
    Last Post: 16th July 2008, 16:08
  3. QComboBox drop list button events
    By maird in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2007, 19:25
  4. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  5. using QComboBox as an ItemView
    By EricTheFruitbat in forum Qt Programming
    Replies: 3
    Last Post: 24th January 2007, 16:14

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.