Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Handling QListWidget clicking and scrolling

Handling QListWidget clicking and scrolling

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 1 Posters 883 Views 1 Watching
  • 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.
  • P Offline
    P Offline
    peter-70
    wrote on last edited by
    #1

    I have a QListWidget with some items (QListWidgetItem's). Of course, the items have their own controls like buttons, lineedits and so on...

    For my QListWidget I set in constructor:

    this->setAttribute(Qt::WA_AcceptTouchEvents, true);
    this->grabGesture(Qt::TapGesture, Qt::IgnoredGesturesPropagateToParent | Qt::ReceivePartialGestures);
    

    Essentially the problem is my event handling:

    bool ListControl::event(QEvent* e)
    {
        auto event = e->type();
        if (event == QEvent::TouchBegin)
        {
            auto touch = dynamic_cast<QTouchEvent*>(e);
            if (touch)
            {
                return this->HandleTouch(touch, event);
            }
        }
    
        ...some code comes here...
    
        return QListWidget::event(e);
    }
    

    When I return on QEvent::TouchBegin the HandleTouch-Method, then I can move the list of elements (QListWidgetItems). With "move" I mean scrolling the list, with my finger on the mobile phone-touch screen. But then I can't get focus on any control of any QListWidgetItem.

    When I return on QEvent::TouchBegin QListWidget::event(e), then I get focus on the controls, but I can no more scroll the list.

    I tried a lot, but nothing helped. How could I solve this problem, to move/scroll the list with my finger, but also can get focus to the controls, on taping on it.

    Supplement: I measure the tap-duration. If it was less than 150ms, then I get the QWidget that was clicked. Only I do not manage to send the widget a message, so that it reacts.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      peter-70
      wrote on last edited by peter-70
      #2

      Ok, I've got a solution! Quick and dirty explained... the trick is in the touch handler (QEvent::TouchBegin), you must set the focus, to the taped widget. If the widget is for example a QPushButton, you must return false, otherwise true. These solution works for me!

      const auto posf = event->touchPoints().first().pos();
      QPoint position(posf.x(), posf.y());
      
      auto widget = this->childAt(position);
      if (widget)
      {
          widget->setFocus();
          widget->activateWindow();
          widget->raise();
      }
      
      auto button = dynamic_cast<QPushButton*>(widget);
      result = (button == nullptr);
      

      Maybe I can help someone

      1 Reply Last reply
      1

      • Login

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