Results 1 to 2 of 2

Thread: QTableView Handling MouseEvent

  1. #1
    Join Date
    Sep 2015
    Posts
    1
    Platforms
    Windows

    Default QTableView Handling MouseEvent

    The Environment:
    - OS: Windows 7 64-bit
    - QT Version: QT 5.4.1
    - Compiler: win64_vc11.0

    The Scenario:
    I have used Qt Designer to create a QDialog which contains several nested layouts containing multiple QTableViews. I am using CMake to create my Visual Studio project. In this process, CMake "build" the .ui file into the appropriate C++ files.

    The Need:
    I want to be able to handle a mouse click on one of those tables and know which cell was clicked.

    The Problem
    When I use "setMouseTracking(true)" on the containing dialog, it does not handle mouse clicks on the previously mentioned QTableView.

    My First Solution (and why it doesn't work):
    My first thought was to extend QTableView with my own class so that I could override the "mousePressEvent()" function, but the QTableView is "built" by CMake, so I can't just replace it with my own class which extends QTableView or I loose the position and settings configured in QtDesigner.


    Does anyone have any idea how I can solve my problem?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableView Handling MouseEvent

    Quote Originally Posted by EvanPlett View Post
    The Need:
    I want to be able to handle a mouse click on one of those tables and know which cell was clicked.
    A very common need, that's why the view has a signal for that.

    Quote Originally Posted by EvanPlett View Post
    My first thought was to extend QTableView with my own class so that I could override the "mousePressEvent()" function, but the QTableView is "built" by CMake, so I can't just replace it with my own class which extends QTableView or I loose the position and settings configured in QtDesigner.
    If you want to do it that way, use the "promote widget" functionality to promote the tableview in design to your class.

    Cheers,
    _

Similar Threads

  1. Replies: 0
    Last Post: 13th June 2015, 20:20
  2. qt mouseEvent
    By lapdx in forum Qt Programming
    Replies: 0
    Last Post: 8th November 2012, 13:37
  3. Handling mouseevent in Qstatusbar .
    By riarioriu3 in forum Qt Programming
    Replies: 1
    Last Post: 12th July 2012, 10:30
  4. Handling mass data with QTreeView/QTableView
    By alsuffndruff in forum Qt Programming
    Replies: 1
    Last Post: 1st October 2006, 23:33
  5. MouseEvent & QTextEdit
    By Sarma in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2006, 23:06

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.