[Interest] Set QTableWidgetItem checkbox when clicking anywhere on QTableWidget's row
Murphy, Sean
smurphy at walbro.com
Thu Jul 6 15:34:52 CEST 2017
> You can set a flag if the button was "released" (i.e. by the user), and in your
> slot set the checkbox only if the flag wasn't set but in any case reset the flag.
>
> Or you can use the sender() function to see which object activated your slot.
Thanks for replying, I'll look into this, but I have my doubts for a couple of reasons, unless I'm just not seeing what you mean.
I don't think that a checkable QTableWidgetItem is an actual QCheckbox, is it? So I'm not seeing any way to tell when the "button" was pressed or released, because it doesn't appear that the QTableWidgetItem is a standalone QWidget (or even QObject for that matter) that you can connect to.
And then as far as using QObject::sender(), the only connection I was making is
connect(ui->myTable, &QTableWidget::cellClicked,
this, &myDialog::slotItemClicked);
With that signal, regardless of where the user clicks, whether it's on the checkbox itself or elsewhere in the row, the sender is always a QTableWidget object, leaving me with no real way to tell whether the user clicked on the checkbox itself or somewhere else in the table.
Right now, I'm looking at QTableWidget's itemChanged(QTableWidgetItem* item) signal to see whether it can help. It appears that it does fires in two cases (at least the way I'm using the table): when the checkbox is clicked and when I create/change the checkbox item itself. So I think with some connect()/disconnect() tweaking I can get that to help me figure out where the user actually clicked and whether I need to take further action or not. I think I want to disconnect the signal when I'm populating the table with data, I don't care about those item changes, and then after table population I can reconnect the signal so that I'm only triggering when the user clicks on the QTableWidgetItem's check box which appears to emit the itemChanged() signal.
Unless you've got other thoughts?
Sean
More information about the Interest
mailing list