PDA

View Full Version : Removing Focus from QTableWidget



kapoorsudhish
22nd October 2009, 13:32
Hi,
I am new to Qt Environment, i am using a QTablewidget, where i have some some rows and some columns, when the tableWidget was created from QTableWidget, the focus property was set as

tableWidget->setFocusPolicy(Qt::NoFocus );

But still when a cell is clicked on the table, the cell is getting highlighted . Can anyone share as to what can be the reason for the focus not getting cleared from the tableWidget.

Adding the code


{
tableWidget = new QTableWidget(4, 4,RenderScheduleLayout );
QRect rect(40,100,650,200);
tableWidget->setGeometry(rect);
for (int i =0; i < 4; i++)
tableWidget->setColumnWidth(i,50);
for (int i =0; i < 4; i++)
tableWidget->setRowHeight(i,20);

tableWidget->setFocusPolicy(Qt::NoFocus)

connect(tableWidget,SIGNAL(cellClicked(int,int)),t his,SLOT(doSomething(int,int)));
}

void Widget::doSomething(int row, int column){

QTableWidgetItem *newItem = new QTableWidgetItem(tr(""));
newItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
tableWidget->setItem(row, column, newItem);
tableWidget->clearFocus();
}

I am also doing a clear focus on this but still the focus on the selected cell is shown, i dont know how to remove the focus as its not being removed using tableWidget->setFocusPolicy(Qt::NoFocus)

Please help me on this issue.

Lykurg
22nd October 2009, 14:04
Focus and selection are two different things. Use

newItem->setFlags( /*Qt::ItemIsSelectable |*/ Qt::ItemIsEnabled );

kapoorsudhish
22nd October 2009, 15:16
Thanks Lykurg, it worked. It will also be good if you can help me on thread

http://www.qtcentre.org/forum/f-newbie-4/t-how-to-access-widgets-created-in-tab-view-24993.html

Thanks.