Results 1 to 2 of 2

Thread: How to get text for Tableview to Combobox ?

  1. #1
    Join Date
    Dec 2011
    Posts
    14
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to get text for Tableview to Combobox ?

    I loaded a Form with tableview have data (data loaded from MYSQL ), when a row on tableview is selected, data from each column will display on LineEdit ( Mã DL, Tên DL, Email, Địa chỉ, Điện thoại, Tiền nợ ) and also display on DateEdit ( Ngà y nháº*n ) but can not display on 2 Combobox ( Loại DL, Tên quáº*n ). See pic :

    2.jpg


    Combobox "Loại DL, Tên quáº*n" display " 1, Quan 1" is default Items, can not diaplay for tableview. These are code :

    Qt Code:
    1. connect(ui.tableView->selectionModel(),SIGNAL(selectionChanged(const QItemSelection &,const QItemSelection &)),this,SLOT(selectItem(const QItemSelection &,const QItemSelection &)));
    2. ui.tableView->selectRow(0);
    3.  
    4.  
    5. void QuanLyDaiLy::selectItem(QItemSelection selected,QItemSelection)
    6. {
    7. QSqlQueryModel *QModel;
    8. QModelIndexList items = selected.indexes();
    9. ui.txtMaDL->setText(QModel->data(items[0],Qt::DisplayRole).toString());
    10. ui.txtTenDL->setText(QModel->data(items[1],Qt::DisplayRole).toString());
    11. ui.txtEmail->setText(QModel->data(items[2],Qt::DisplayRole).toString());
    12. ui.txtDiaChi->setText(QModel->data(items[3],Qt::DisplayRole).toString());
    13.  
    14. QModelIndexList mySelection4 = ui.tableView->selectionModel()->selectedRows(4);
    15. QDate data4;
    16. foreach(QModelIndex selectedIndex4, mySelection4)
    17. data4 = selectedIndex4.data(0).toDate();
    18. ui.dtNgayNhan->setDate(data4);
    19.  
    20. ui.cbLoaiDL->itemText(QModel->data(items[5],Qt::DisplayRole).toInt());
    21. ui.cbTenQuan->setCurrentIndex(QModel->data(items[6],Qt::DisplayRole).toInt());
    22.  
    23. ui.txtDienThoai->setText(QModel->data(items[7],Qt::DisplayRole).toString());
    24. ui.txtTienNo->setText(QModel->data(items[8],Qt::DisplayRole).toString());
    25. }
    To copy to clipboard, switch view to plain text mode 

    ui.cbLoaiDL->itemText(...
    ui.cbTenQuan->setCurrentIndex(..

    itemText() and setCurrentIndex() functions are not work , which functions I can use ?

    Thanks for help !

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to get text for Tableview to Combobox ?

    See QDataWidgetMapper, which is the "right" way to do what you want.

    And no wonder that setCurrentIndes is not working. Debug what QModel->data(items[6],Qt:isplayRole) returns! It is "quan 2" which is not a number....

  3. The following user says thank you to Lykurg for this useful post:

    hohoanganh205 (26th December 2011)

Similar Threads

  1. Replies: 1
    Last Post: 8th April 2011, 19:54
  2. Clearing editted text from ComboBox on return
    By cnbp173 in forum Qt Programming
    Replies: 2
    Last Post: 3rd February 2011, 22:41
  3. Replies: 0
    Last Post: 31st October 2010, 21:55
  4. centering combobox text
    By illuzioner in forum Qt Programming
    Replies: 4
    Last Post: 30th May 2007, 14:06
  5. Replies: 8
    Last Post: 15th May 2007, 09:21

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.