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. QItemDelegate with multiple QWidgets inside - Focus problem
Qt 6.11 is out! See what's new in the release blog

QItemDelegate with multiple QWidgets inside - Focus problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 1.2k Views 2 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.
  • gde23G Offline
    gde23G Offline
    gde23
    wrote on last edited by
    #1

    Hello,

    I have a QStyledItemDelegate with a custom pain event that holds several other widgets. Now when the delegate is clicked the focus jumps to the delegate. However it should be at the underlying widget that was clicked on.
    If there is only one widget I can achieve the desired behaviour by delegateWidget->setFocusProxy(the_editor_widget);
    However this naturally only works for one widget. Is there some method to "forward" the click to the underlying widget?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
      wrote on last edited by
      #2

      Are you looking for event filters ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      https://www.pthinks.com

      1 Reply Last reply
      0
      • gde23G Offline
        gde23G Offline
        gde23
        wrote on last edited by
        #3

        If eventFilters are the solution, then maybe.
        But I do not know how exactly to solve it with event filters.

        The QTreeView::mousePressEvent()
        triggers QStyledItemDelegate::createEditor(); and QStyledItemDelegate::setEditorData();.
        However, now the click needs to kind of be repeated on the created editor Widget.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          One possibility could be to use QApplication::widgetAt in your editor showEvent and check there which widget is under the cursor to give it the focus.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • gde23G Offline
            gde23G Offline
            gde23
            wrote on last edited by
            #5

            @SGaist: Thanks for the hint, however qApp->widgetAt(QCursor::pos()); returns the viewport of the TreeView (qt_scollarea_viewport) instead of the widget inside the delegate.

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              I had similar problem and went through couple of different solutions. My case was specific in the sense that I only wanted the edit to start via mouse press, not other methods (i.e. enter or tab). In that specific case I ended with the following:

              Blocked all edit triggers by setting editTriggers to NoEditTriggers.
              Implemented editorEvent() in the delegate to recognize a mouse press and calling edit() manually.
              In the created widget I implemented showEvent(). In it I check if it's the first show event or not. If it's the first I synthesize a fake mouse release event followed by a mouse press event and send them to the app via QApplication::sendEvent(). Some attention was needed to make sure the fake events are with the same mouse buttons and other event options, otherwise you can easily confuse the internals of the view.

              This way Qt does all the work to figure out which widget should get the focus and mouse press, how to route it through the item view etc. You can probably extend this to other trigger methods. You would just need to tell the widget somehow about which trigger method was used and act accordingly in the showEvent() e.g. set focus on the "first" widget when it's via tab key and so forth.

              1 Reply Last reply
              3

              • Login

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