Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with reimplementation of event() in QTableView subclass
Forum Update on Monday, May 27th 2025

Problem with reimplementation of event() in QTableView subclass

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 929 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    A1exander_Z
    wrote on last edited by
    #1

    I am developing a cross-platform application which should also work on tablets. There is a couple of context menus (created using Qt::ActionsContextMenu policy) and I want them to appear on tablets by tap and hold gesture.

    In one case the menu belongs to a custom widget subclassed from QWidget. I have reimplemented the event handler in the following way:

    @bool MyWidget::event(QEvent event)
    {
    if (event->type() == QEvent::Gesture)
    {
    QGestureEvent
    gEvent = static_cast<QGestureEvent*>(event);
    if (gEvent->gesture(Qt::TapAndHoldGesture) != NULL)
    {
    QTapAndHoldGesture gesture =
    static_cast<QTapAndHoldGesture
    >(
    gEvent->gesture(Qt::TapAndHoldGesture));
    if (gesture->state() == Qt::GestureFinished)
    {
    QContextMenuEvent menuEvent(QContextMenuEvent::Other,
    mapFromGlobal(gesture->position().toPoint()),
    gesture->position().toPoint());
    QApplication::sendEvent(this, &menuEvent);
    }
    gEvent->accept();
    }
    return true;
    }
    else return QWidget::event(event);
    }@

    It works as expected, no problems.

    Another menu belongs to QTableView. I have subclassed it and reimplemented the event handler in the same way, except for the last line:

    @return QTableView::event(event);@

    I does not work at all, the menu is never shown, despite the fact that the QContextMenuEvent event is sent. If I change QTableView::event(event) call to QWidget::event(event), the menu is shown, but, obviously, some parts of the table are not rendered, because some paint events are not processed. Any ideas?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      A1exander_Z
      wrote on last edited by
      #2

      After some experiments I have found that changing the last line to these two does the job:

      @else if (event->type() != QEvent::ContextMenu)
      return QTableView::event(event);
      else
      return QWidget::event(event);@

      Still, I do not understand why QTableView does not process ContextMenu events.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved