How can achieve this in Qtablewidget?
-
Hi!
I am stuck and don't know how to get this operation with Qtablewiget, I have a Qtablewidget which displays data in three columns (data is displayed on cells containing QlindEdit). At start when Qtablewidget appear, I want the very first cell (with QlineEdit) should get focus and then I can use downarrow key to move to every column cell containing QlineEdit. My QTablewidget has 10 rows and 3 columns, everycell in columns contain QlineEdit widget. I want when the focus reach to last cell of column via downarrow key, it should move to first cell of second column in tablewidget. I don't know to to achieve this.Can anyone tell me the solution or share any example related to the solution as reference, I will be very helpful for me. I have shared screen shots of my table and the table I want to create like.
Thank you in advance!
my code:
{
ui->setupUi(this);col = 0; row = 0; ui->tableWidget->setColumnWidth(0, 107); ui->tableWidget->setColumnWidth(1, 200); ui->tableWidget->setColumnWidth(2, 107); ui->tableWidget->setColumnWidth(3, 200); ui->tableWidget->setColumnWidth(4, 107); ui->tableWidget->setColumnWidth(5, 200); for(row=0; row < 10; row++) { ui->tableWidget->setRowHeight(row, 40); } for(row=0; row<10; row++) { for(col = 0; col<6; col++) { if(col==1) {ui->tableWidget->setCellWidget(row, col, new QLineEdit());} if(col==3) {ui->tableWidget->setCellWidget(row, col, new QLineEdit());} if(col==5) {ui->tableWidget->setCellWidget(row, col, new QLineEdit());} } } ui->tableWidget->setFocus(); ui->tableWidget->setCurrentCell(0,1);// if (col==1 && row==9)
// {
// ui->tableWidget->setCurrentCell(0,3);
// ui->tableWidget->setFocus();
// }}


-
Hi,
Since you are covering your table view with widgets, you will have to use an event filter to capture the keys of interest and move the focus around.
That said, why do you need that many QLineEdit ?
Can't you use a custom edit trigger to fulfill your needs ? -
Hi,
Since you are covering your table view with widgets, you will have to use an event filter to capture the keys of interest and move the focus around.
That said, why do you need that many QLineEdit ?
Can't you use a custom edit trigger to fulfill your needs ?@SGaist Thank you for your suggestion, now i am trying event filter , let see if it works. Everycolumn cell have data in edit, which is editable that is why i am using QLine Edit in every cell in column.
Here is what i am trying to do now, hope it will work:

-
The thing is: the QTableView already has editing support so putting QLineEdits everywhere is not necessary.
-
The thing is: the QTableView already has editing support so putting QLineEdits everywhere is not necessary.
@SGaist You are right, but this time I am trying to move my focus on first cell of column third, as the focus reached at last cell of column first using downarrow key, it (focus) should move to first cell of third column. until now I am unable to achieved it.
-
@SGaist You are right, but this time I am trying to move my focus on first cell of column third, as the focus reached at last cell of column first using downarrow key, it (focus) should move to first cell of third column. until now I am unable to achieved it.
-