How to throw cell click event of QTable Widget
-
What about setCurrentItem()?
-
Why do you want to emulate a click?
to set the input focus?
to start editing a cell?What is the use case?
-
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. -
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!
-
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. -
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)@
-
Hi Iktwo
setSelected(true)
is working but it is not removing selection of previous row.
Here user gets a feel of two are selected . -
Sorry for that, maybe @void setCurrentCell ( int row, int column )@
-
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.
-
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. -
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.