PDA

View Full Version : Set Foucus Out Of QtableView



ShapeShiftme
18th August 2011, 08:24
Good Day All.

I have an interesting problem that i hope is simple.

I have a table that when a certain cell is blank it triggers the following function:



void myfrm::cellIsEmpty()
{
//Run if the item cell is empty
qDebug()<< "Im A Empty Cell";
ui->tableview->viewport()->setFocusPolicy(Qt::NoFocus); //tried with and without does not work
ui->in_total->setFocus();

}

Results: When the function runs i do see the qdebug "Im A Empty Cell" So i know the functions is being called however the focus of the application remains on the next field of the tableview.

Expected Result:
I expect the focus to be on the lineedit "in_total" For editing


Any Help Would be appreciated.


Regards

ShapeShiftme
6th October 2011, 05:11
Good day. Im bumping this as i still do not know how to do it.

Could someone please help

ChrisW67
6th October 2011, 06:14
How and when is the function being called?

ShapeShiftme
6th October 2011, 07:07
void form1::mycellChanged(int myrow, int mycol)
{
QTableWidgetItem *celldata = ui->table_items->item(myrow,0);
QString mycode = celldata->text();
if(mycode!="")
{
//othercodehere
}
else{
cellIsEmpty();
}
}

void form1::cellIsEmpty()
{
//Run if the item cell is empty
qDebug()<< "Im A Empty Cell";
ui->table_items->viewport()->setFocusPolicy(Qt::NoFocus);
//viewport()->setFocusPolicy(Qt::NoFocus);
ui->in_total->setFocus();

}




Is there anyhting else you need as you can see in my commented code i have tried a couple of things but i cant get it to work

Regards

ShapeShiftme
17th November 2011, 12:35
BUMP. Months with no help. Can Anyone please have a look at it

myta212
21st November 2011, 17:15
Hi,
Are you have create signal and slot for your QTableWidget in your code ?
you can add this code in your code :

//Create Signal and slot for QTableWidget
connect(ui->tableWidget, SIGNAL(cellChanged ( int, int)), this, SLOT(mycellChanged(int, int)));

and implement mycellChanged slot like this :

//show debug information when QTableWidgetItem Changed
void basicQTableWidget::mycellChanged(int myrow, int mycol)
{
QTableWidgetItem *celldata = ui->tableWidget->item(myrow, mycol);
if(celldata->text()!="")
{
qDebug()<<"Table Position [" + QString::number(myrow) +
", " + QString::number(mycol) + "] = " + celldata->text();
}
else
{
qDebug()<<"Table Position [" + QString::number(myrow) + ", " +
QString::number(mycol) + "] is Empty";
}

}

you can get the complete source code in here : http://toto-share.com/2011/11/qt-qtablewidget-tutorial

Are this website address solve your problem ?

Best regards,

Toto

ShapeShiftme
22nd November 2011, 03:46
Hi,
Are you have create signal and slot for your QTableWidget in your code ?
you can add this code in your code :

...


Are this website address solve your problem ?

Best regards,

Toto

This does not help at all.
I don't think you even read the posts
If you did you can see that i do everything you suggest.
. I can use a table i just need to move the focus out of the table once we have finished doing my tests.

marcvanriet
23rd November 2011, 00:02
Just a guess.. maybe changing the focus in an event that occurs when the focus is just changes gives you a problem ?

You might try to start a single shot timer instead of doing ui->in_total->setFocus();
Then in you timer event code, do ui->in_total->setFocus();

Regards,
Marc

norobro
23rd November 2011, 00:58
Another guess - You're not confusing focus with the highlight of the selected cell, are you? If you type something in does it show up in the lineEdit? If that's the case put the following in your slot:
ui->table_items->clearSelection();