Results 1 to 3 of 3

Thread: QTableWidget and QCombobox

  1. #1
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default QTableWidget and QCombobox

    Hi to all!

    I am facing a problem of retrieving all items from a given column of a QTableWidget to a QComboBox. The problem itself appears when I diplay the retrieved items in the ComboBox, because their number get increased. For instance, if I have three rows and four columns, three items are displayed repeately up to twelve in total. I just wanted to have three items corresponding to the number of the rows.

    Some precisions:

    1- Name is the name of the column fron wich the items should be selected.
    2- m_details is my combobox.
    3- m_tableau is my TableWidget.

    Even the function:
    Qt Code:
    1. m_details->setDuplicatesEnabled(false);
    To copy to clipboard, switch view to plain text mode 
    does not solve the problem.

    Could someone have a look on my peace of code and propose me an advice? I would be greatefull.

    Here is my code:

    Qt Code:
    1. for(int y = 0; y<m_tableau->rowCount(); y++)
    2. {
    3. for(int x = 0; x<m_tableau->columnCount(); x++)
    4. {
    5. valCol = m_tableau->horizontalHeaderItem(x);
    6. valColConver = valCol->text();
    7.  
    8. if(valColConver == "Name")
    9. {
    10. valCell = m_tableau->item(y, x);
    11.  
    12. if(valCell != NULL)
    13. {
    14. valConver = valCell->text();
    15.  
    16. listeItem.push_back(valConver);
    17.  
    18. m_details->addItems(listeItem);
    19.  
    20. valConver.clear();
    21. valColConver.clear();
    22. }
    23. }
    24.  
    25. }
    To copy to clipboard, switch view to plain text mode 

    Many thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget and QCombobox

    You call addItems in the inner loop, always with the same list instance. So every call to addItems add again all the previously added ones.

    Just move the call to addItems to after the outer loop.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2012
    Posts
    83
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget and QCombobox

    Dear Anda_skoa,

    when I am reading your post, I just want to say YES!!!!!!!!!!!!!!!!!!!!!!!! and finaly I say it!!!

    Many thnaks! It works perfectly!

    Many many thanks!

Similar Threads

  1. Replies: 1
    Last Post: 20th June 2013, 07:24
  2. Again QTableWidget and QComboBox delegate
    By Aki-Matti in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2008, 14:40
  3. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2007, 00:29
  4. Adding QComboBox to QTableWidget very slow
    By munna in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2006, 16:45
  5. QComboBox inside QTableWidget
    By campana in forum Qt Programming
    Replies: 7
    Last Post: 20th March 2006, 18:22

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.