Results 1 to 4 of 4

Thread: Getting item from QTableView when clicked on

  1. #1
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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 :

    Qt Code:
    1. if( event->type() == QEvent::MouseButtonPress )
    2. {
    3. QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
    4. QPoint index = helpEvent->pos();
    5. QModelIndex item = indexAt( index );
    6. if( item.isValid() )
    7. {
    8. CDADcb::CSignal* pSignals;
    9. pSignals = (CDADcb::CSignal*)theApp->m_dcb.GetSignalList()->at(item.row());
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Getting item from QTableView when clicked on

    Viewport event? What for? can't you connect to the clicked(QModelIndex) signal?

  4. #4
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

    Many thanks,
    Steve

Similar Threads

  1. Dragging an item from QTableView to a QPushButton
    By steg90 in forum Qt Programming
    Replies: 2
    Last Post: 23rd May 2007, 11:57
  2. Replies: 1
    Last Post: 19th April 2007, 22:23
  3. Replies: 17
    Last Post: 31st March 2006, 05:57
  4. how change the QListBox item position by pixel
    By roy_skyx in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 01:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.