PDA

View Full Version : QTableView deselecting on click



andytork
19th January 2009, 07:38
Hi,

Is there a way I can remove the selection when clicked away from an item, by that I mean in an area of the table with no items or outside the table (on a lost focus)

I can't find any signals anywhere to help me with this

Any help appreciated

Thanks

Andy

wysota
19th January 2009, 08:09
You have to reimplement mouseReleaseEvent and do the deselection yourself based on whether you click on the item or not (QAbstractItemView::itemAt() will be helpful to determine this).

andytork
19th January 2009, 09:53
Thanks for the help, I used the following which looks good


void JournalView::mouseReleaseEvent ( QMouseEvent * event )
{
QModelIndex idx = indexAt(event->pos());
if (idx.isValid())
{
qDebug() << "Valid";
}
else
{
qDebug() << "Invalid";

}
}

wysota
19th January 2009, 14:14
Remember to call the base class implementation.

miraks
19th January 2009, 17:51
You can find the solution here:
http://www.qtcentre.org/forum/f-newbie-4/t-deselect-lines-in-table-views-17983.html