How to throw cell click event of QTable Widget
-
wrote on 20 Oct 2011, 09:52 last edited by
Hi All
I have created one QTableWidget.
I have one function in which I am performing some operations.
When this operation is successfull I want the CellClick event on first row of Table.
How to do this? -
wrote on 20 Oct 2011, 10:17 last edited by
Please rephrase your question. There is no CellClick event that can be on a row or something like that.
-
wrote on 20 Oct 2011, 10:26 last edited by
Hi Andre
I mean to say cell click for (0,0)Cell in the Table widget.
-
wrote on 20 Oct 2011, 11:05 last edited by
Do I understand correctly:
You want to have some function like this:
@
<whatever type> foo()
{
// do some work here
// simulate a mouse click event on a specific cell of a table
// do something else
}
@ -
wrote on 20 Oct 2011, 11:14 last edited by
Yes Gerolf.
-
wrote on 20 Oct 2011, 11:18 last edited by
What about setCurrentItem()?
-
wrote on 20 Oct 2011, 11:57 last edited by
Why do you want to emulate a click?
to set the input focus?
to start editing a cell?What is the use case?
-
wrote on 21 Oct 2011, 02:36 last edited by
Hi Gerolf
On the click of the particular cell I am reading the data of that row.
So By default i want to read the data of 1st row.
code to read the data is implemented in the SLOT of cell click. -
wrote on 21 Oct 2011, 03:19 last edited by
Hi, I I did something similar with QTableWidget and I used cell clicked signal
(http://doc.qt.nokia.com/latest/qtablewidget.html)
@void cellClicked ( int row, int column )@if I understand you correctly you want to trigger the signal for the a particular cell (in the first post you said row, it may have confused some) if you have connected the signal and slot, you should be able to call the slot with row 1 and column 1.
I have something like this
@void VenVisReservaciones::on_tblReservaciones_cellClicked(int row, int column){
..
}@So if I finish processing data I do something like this
@
on_tblReservaciones_cellClicked(1,1);
@If you want to click a cell and then you want to read the first cell of that row, then you can do something like this:
@void VenVisReservaciones::on_tblReservaciones_cellClicked(int row, int column){
process(ui->tblReservaciones->item(1,row)->text());
..
}process(QString text){
..
}
@Hope it helps you!
-
wrote on 21 Oct 2011, 04:29 last edited by
Hi IKtwo
Thanks it worked.
But now I also want the focus to be on 1st row[i.e it should show as 1st row is selected]
How to do that. -
wrote on 21 Oct 2011, 05:21 last edited by
I'm not sure if a Cell has a method called setFocus(), you can try it, something like
@ui->table->item(X,Y)->setFocus();@
If that doesn't work maybe @setSelected(true)@
-
wrote on 21 Oct 2011, 05:38 last edited by
Hi Iktwo
setSelected(true)
is working but it is not removing selection of previous row.
Here user gets a feel of two are selected . -
wrote on 21 Oct 2011, 06:27 last edited by
So putting it together:
setFocus for the table
setCurrentCell()in combination should set the current cursor position to the specified cell.
If you want to clean any selection before, do it via the selectionModel.
-
wrote on 21 Oct 2011, 07:13 last edited by
Hi Gerolf
Its not working,I m doing something like this
@
on_AE_Tablecell_Clicked(0,0);//This is the slot i want to be called
ui.tableWidget_AE->setCurrentCell(0,0,QItemSelectionModel::Rows);
@
By doing this it only setting the focus to (0,0) item but i want to show that complete row as blue and other previous selection should be removed. -
wrote on 21 Oct 2011, 09:11 last edited by
selectRow(0) is the slot to use.
You could have found yourself very easily if you had scanned through the fine API documentation of [[Doc:QTableWidget]] and its base classes [[Doc:QTableView]] and [[Doc:QAbstractItemView]]. Finding that slot with a quick search in the browser is a no brainer.
1/16