PDA

View Full Version : Getting item from QTableView when clicked on



steg90
23rd May 2007, 12:44
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 :



if( event->type() == QEvent::MouseButtonPress )
{
QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
QPoint index = helpEvent->pos();
QModelIndex item = indexAt( index );
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

marcel
23rd May 2007, 12:56
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.

wysota
23rd May 2007, 12:56
Viewport event? What for? can't you connect to the clicked(QModelIndex) signal?

steg90
23rd May 2007, 12:58
Hi,

I have just done what you said wysota! I always seem to do things the hard way :o

Many thanks,
Steve