Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED] QCheckBox in a QTableWidget



  • i created a simple loop in a QTableWidget with checkboxes but i dont know how i get their objectnames.

    @
    for (int i=0; i < total_items; i++) {
    QCheckBox *cb = new QCheckBox();
    tableWidget->setCellWidget(i, 0, cb);
    tableWidget->setItem(i, 1, new QTableWidgetItem("name" + i));
    }
    @

    when i click the OK button, i want to detect if the checkboxes are checked or not but i dont have any idea how to get their objectnames.

    hope you could give some advices on how to deal with this. thank you.



  • i tried using QSignalMapper but i only know QSignalMapper using strings but with boolean, i dont know..



  • You can simply loop over the items again, right? Either you store pointers to the checkboxes separately (in a QList<QCheckBox*> or a QVector<QCheckBox*>, or you simply retreive the pointer to the widget again from your tablewidgetitem and cast it to a QCheckBox* again.

    Note: QTableWidget can also display checkboxes by itself. No separate widgets needed...



  • thanks for giving me an idea.



  • Do you know of the "Qt::ItemIsUserCheckable":http://doc.qt.nokia.com/4.7/qt.html#ItemFlag-enum flag for table wiget items (and all other item view/widget classes)?



  • can QTableWidget display checkboxes by itself without the need of seperate widgets ?
    plz tell me how.



  • [quote author="poketmonister" date="1396440874"]can QTableWidget display checkboxes by itself without the need of seperate widgets ?
    plz tell me how.[/quote]

    Yes, and the link Volker gave tells you how.



  • i'll checkout Qt::ItemIsUserCheckable .

    by the way QList<QCheckBox*> worked wonders thanks.


Log in to reply