Results 1 to 1 of 1

Thread: how to set QComboBox on qsqlquerymodel header

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Unhappy how to set QComboBox on qsqlquerymodel header

    Hi,

    I need to show the combobox widget on a qsqlquerymodel header. (in the second column header)
    In my code i overrided the headerData() method.
    But combobox is not coming.Its showing empty.

    My Code,

    Qt Code:
    1. UserQueryModel *model = new UserQueryModel (ui.table);//derived from qsqlquerymodel class
    2. model->setQuery("select * from sf_search");
    3. ui.table->setModel(model);
    4.  
    5.  
    6. class UserQueryModel:public QSqlQueryModel
    7. {
    8. public:
    9. QTableView *mTable;
    10. QVariant variant;
    11. QWidget widget;
    12.  
    13. UserQueryModel(QTableView *table)
    14. {
    15. mTable = table;
    16.  
    17. QHBoxLayout *layout = new QHBoxLayout(&widget);
    18. QComboBox *box = new QComboBox(&widget);
    19. layout->addWidget(box);
    20. variant.setValue(&widget);
    21.  
    22. }
    23.  
    24. QVariant headerData( int section, Qt::Orientation orientation, int role) const
    25. {
    26. if(section == 2 && (orientation == Qt::Horizontal))
    27. {
    28. return variant;
    29. }
    30. return QSqlQueryModel::headerData(section, orientation, role);
    31. }
    To copy to clipboard, switch view to plain text mode 
    Can somebody help me with this??
    Last edited by jpn; 24th July 2009 at 22:24. Reason: missing [code] tags

Similar Threads

  1. How to edit Horizontal Header Item in QTableWidget
    By ioannis in forum Qt Programming
    Replies: 6
    Last Post: 5th March 2013, 18:50
  2. QComboBox QSqlQueryModel
    By aekilic in forum Qt Programming
    Replies: 8
    Last Post: 17th December 2008, 12:01
  3. QComboBox drop list button events
    By maird in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2007, 19:25
  4. QComboBox QSqlQueryModel & relation.
    By matheww in forum Qt Programming
    Replies: 2
    Last Post: 20th June 2007, 04:56
  5. Replies: 0
    Last Post: 10th November 2006, 13:46

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.