QTableWidget items selection

  • Gents;

    I am doing an exercice using QTableWidget when I have to select one item from four in each row of the first column. Lets say I have 10 rows and 3 columns. I thought of crearing a QStringList that I attribute to each row and select the item, like QCombo Box widget.

    I have prepared the below exemple; please advise:

    list->append("Item 1");
    list->append("Item 2");
    list->append("Item 3");
    list->append("Item 4");

    for(int i = 0; i < 1; i++ )
    for (int j = 0; j < 11; j++)
    Stagetype = new QTableWidgetItem (QStringList (list));



  • Lifetime Qt Champion


    Advise what exactly ?

  • @SGaist
    When running this code I had a couple of error messages. I am not sure this is the proper way to proceed.


  • Qt Champions 2017

    Hi, if you list the actual errors we can help make them go away :)
    (you can right click error and say copy, in Creator)


    Your sample seems to be missing
    This is important as nothing will show otherwise :)

  • @mrjj this is my code:

    void CFAdvisor::setupTableItems()
    for (int row = 0; row < table_ConvDesign->rowCount()-1; ++row)
    for (int column = 0; column < table_ConvDesign->columnCount()< 0; ++column)
    QStringList list;
    table_ConvDesign->setItem(row, column, &list);
    and this is the error:
    E:\Computing\Qt Designer\cfadvisor.cpp:168: erreur : no matching function for call to 'QTableWidget::setItem(int&, int&, QStringList
    table_ConvDesign->setItem(row, column, &list);

  • Lifetime Qt Champion

    setItem takes a QTableWidgetItem * not a QStringList *.

  • @SGaist this is the point; how to make it take a QStringList. This is what I want to do ;)

  • Qt Champions 2017

    It does not work that way at all. :)
    So even its Xmas, it not possible
    setItem wants an item. not list.
    the item take some text.
    so you can use a for loop with the list, and create item for each.
    It will not do it for you :)

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.