Hello
I have a QTableWidget that is composed of 4 columns and several rows.
2 columns are filled with QTableWidgetItems, it's just text.
2 columns are filled with QComboBoxes.
So, when I want to add a row in my table, I use the setItem function in order to add the 2 QTableWidgetItems. That's ok.
After that I need to add the 2 QComboBoxes, and I do it with the setCellWidget function. That's ok too.
My problem is that I need to know which cell has the focus when the user clicks on a button. So I've connected the signal clicked() (from the button) to a slot. The slot loops over the table and look at each row/colum in order to know if the cell has the focus.
For a given cell, I can know if it has the focus doing this :
- if its colum number = 0 or 1 : the cell is a QTableWidgetItem and I can test with :
if ((table->item(row, column))->isSelected() == true)
if ((table->item(row, column))->isSelected() == true)
To copy to clipboard, switch view to plain text mode
- if its colum number = 2 or 3 : the cell is a QComboBox and I can test with :
if ((table->cellWidget(row, column))->hasFocus() == true)
if ((table->cellWidget(row, column))->hasFocus() == true)
To copy to clipboard, switch view to plain text mode
The matter is that the second test is never TRUE.
I've no compilation errors.
If I replace the QComboBoxes by QListWidgets, the test is OK.
I don't understand what's the problem ^_^.
Could you help me, please ?
EDIT : I think that the QComboBoxes lost focus when the user clic the button
I'm under Win2000. I'll try to use signal/slots to detect the last cell that had the focus.
I don't find any QTableWidget signal that is emitted when I clic a cell that contains a QComboBox . I don't know what to do :-/
I could use currentRow() and currentColumn to know the current object positon, but currentColumn doesn't care about the QComboBoxes in my cells... Unlike currentRow() .
.
Bookmarks