Getting item from QTableView when clicked on
Hi,
I have a TableView which is linked to a model. I have overriden viewportEvent in my table view ( for various reasons ) and have added the following piece of code to it :
Code:
if( event
->type
() == QEvent::MouseButtonPress ) {
QHelpEvent *helpEvent
= static_cast<QHelpEvent
*>
(event
);
QPoint index
= helpEvent
->pos
();
if( item.isValid() )
{
CDADcb::CSignal* pSignals;
pSignals = (CDADcb::CSignal*)theApp->m_dcb.GetSignalList()->at(item.row());
}
}
For some reason, I have to click far left of each cell in my table for the model index to be valid, any reason for this or is the above wrong?! Maybe it would be best to emit a signal from my model when item is clicked?
Regards,
Steve
Re: Getting item from QTableView when clicked on
Why do you cast to a QHelpEvent?
Even if you need a help event, a QMouseEvent is what you get. The event type speaks for itself.
Re: Getting item from QTableView when clicked on
Viewport event? What for? can't you connect to the clicked(QModelIndex) signal?
Re: Getting item from QTableView when clicked on
Hi,
I have just done what you said wysota! I always seem to do things the hard way :o
Many thanks,
Steve