QComboBoxes in QTableWidget : which is focused ?
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 :
Code:
if ((table->item(row, column))->isSelected() == true)
- if its colum number = 2 or 3 : the cell is a QComboBox and I can test with :
Code:
if ((table->cellWidget(row, column))->hasFocus() == true)
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 :mad:
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 :o. 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() :crying:.
.
Re: QComboBoxes in QTableWidget : which is focused ?
Quote:
Originally Posted by
Nyphel
EDIT : I think that the QComboBoxes lost focus when the user clic the button :mad:
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 :o. 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() :crying:.
You can connect to one of the slots for QComboBox (like activated), or you could use a QComboBox derivation and re-implement the focusInEvent handler, perhaps emitting your own signal.
The alternative is to develop your own delegate and process focus in events in the event filter.
HTH,
Susan
Re: QComboBoxes in QTableWidget : which is focused ?
Hi,
I can't really use the QComboBox signals/slots, because the user can add rows to my table... And this operation adds QComboBoxes in the cells. Like I don't store them in memory, using vectors for example, I can't say that the signal is connected to each QComboBox.
This is the reason why I would like to detect a focus change : I could go thrut the table and look at each cell in order to know the one that is focused.
Re: QComboBoxes in QTableWidget : which is focused ?
What kind of data does the combo box contain? I'd suggest using a custom delegate or an item editor factory to provide the combo box as a custom editor instead of using cell widgets.
Re: QComboBoxes in QTableWidget : which is focused ?
I only store text in the QComboBoxes :)
That seems very interesting JPN, and there are examples too :D
Thanks a lot, I will give a big look !