Results 1 to 5 of 5

Thread: QCombobox with multiple columns

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    18

    Default Re: QCombobox with multiple columns

    This is attempt 2 (still doesn't compile).

    Can anyone point me in the right direction? I don't have a clue what im doing.

    Qt Code:
    1. void SerialNumberProg::columnsTrial(
    2. ) {
    3.  
    4. if( ( tw = new QTableWidget( 0, 2, m_qtapp )) != NULL ) {
    5.  
    6. QAbstractItemModel *model = m_qtapp->AllocateEcoComboBox->model();
    7.  
    8. tw->setModel( model );// DOESN'T LIKE THIS LINE...
    9.  
    10. int rowcount = tw->rowCount();
    11. tw->setRowCount( rowcount + 1 );
    12.  
    13. item = new QTableWidgetItem( "id" );
    14. tw->setItem( rowcount, 0, item );
    15.  
    16. item = new QTableWidgetItem( "date" );
    17. tw->setItem( rowcount, 1, item );
    18.  
    19. m_qtapp->AllocateEcoComboBox->setView( tw );
    20. delete( tw );
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    18

    Default Re: QCombobox with multiple columns

    If anyone is after a similar topic try searching for setView.

    I got the following to work with ideas from this forum and a colleague.

    I got to make a class for it now.

    Qt Code:
    1. QStandardItemModel *model = new QStandardItemModel( 3, 2, this );
    2. for (int i = 0; i < model->rowCount(); ++i) {
    3. QStandardItem* col0 = new QStandardItem( QString("foo%0").arg(i) );
    4. QStandardItem* col1 = new QStandardItem( QString("bar%0").arg(i) );
    5. model->setItem(i, 0, col0);
    6. model->setItem(i, 1, col1);
    7. }
    8.  
    9. QTableView* tableView = new QTableView( this );
    10. tableView->setModel( model );
    11. tableView->verticalHeader()->setVisible(false);
    12. tableView->horizontalHeader()->setVisible(false);
    13. tableView->setColumnWidth ( 0, 60 );
    14. tableView->setColumnWidth ( 1, 160 );
    15. tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    16. tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
    17. tableView->setAutoScroll(false);
    18.  
    19. myComboBox->setModel( model );
    20. myComboBox->setView( tableView );
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 1
    Last Post: 6th December 2012, 19:56
  2. Width QTableView for QCombobox with multiple columns
    By visor_ua in forum Qt Programming
    Replies: 7
    Last Post: 21st June 2011, 10:54
  3. ComboBox with multiple columns
    By haldrik in forum Qt Programming
    Replies: 7
    Last Post: 11th July 2009, 10:15
  4. Need to have columns in QComboBox
    By anju123 in forum Qt Programming
    Replies: 6
    Last Post: 6th July 2009, 22:04
  5. QCompleter on multiple columns
    By akiross in forum Qt Programming
    Replies: 0
    Last Post: 9th November 2008, 16:15

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.