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. How to apply Hover styling when navigating QTreeView via the Keyboard
QtWS25 Last Chance

How to apply Hover styling when navigating QTreeView via the Keyboard

Scheduled Pinned Locked Moved Solved General and Desktop
hoverqt6qtreeview
3 Posts 2 Posters 388 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.
  • J Offline
    J Offline
    Jammin44fm
    wrote on last edited by
    #1

    Hi all,

    In my application I have a QMenu full of menu items, sub menu's etc.
    One of my submenus, contains one of more menu items, and a QWidget.
    The QWidget is in fact a QTreeView, which displays a limited view of some data in a tree.

    When I use the mouse to navigate the Menus, I get the change in background, according to which item
    the mouse is currently over, ie the Hover item.
    I even have this working in the TreeViewWidget which is attached as a Menu Item, by setting the stylesheet

        setStyleSheet("QTreeView::item:hover"
                      "{"
                      "background: #555555;"
                      "}");
    

    However when I navigate the same menus via the keyboard,
    I cannot get the Hover effect to work for the Items in the TreeView.

    So how can I programmatically tell the treeview that a specific QModelIndex should currently have the Hover status applied?
    and thus it will trigger the drawing of that item as desired?

    My theory is to catch the down arrow key press event, when it is on the bottom menu item,
    and then set the focus to the QTreeView Widget Item, and set the Top item in the TreeView to be Hovered.
    ( The QTreeView Widget item lives at the bottom of the menu in question )

    Thoughts?

    jsulmJ 1 Reply Last reply
    0
    • J Jammin44fm

      Hi all,

      In my application I have a QMenu full of menu items, sub menu's etc.
      One of my submenus, contains one of more menu items, and a QWidget.
      The QWidget is in fact a QTreeView, which displays a limited view of some data in a tree.

      When I use the mouse to navigate the Menus, I get the change in background, according to which item
      the mouse is currently over, ie the Hover item.
      I even have this working in the TreeViewWidget which is attached as a Menu Item, by setting the stylesheet

          setStyleSheet("QTreeView::item:hover"
                        "{"
                        "background: #555555;"
                        "}");
      

      However when I navigate the same menus via the keyboard,
      I cannot get the Hover effect to work for the Items in the TreeView.

      So how can I programmatically tell the treeview that a specific QModelIndex should currently have the Hover status applied?
      and thus it will trigger the drawing of that item as desired?

      My theory is to catch the down arrow key press event, when it is on the bottom menu item,
      and then set the focus to the QTreeView Widget Item, and set the Top item in the TreeView to be Hovered.
      ( The QTreeView Widget item lives at the bottom of the menu in question )

      Thoughts?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Jammin44fm If you navigate with the keyboard you do not move the cursor, so nothing is being hovered. But you can change the background of the selected items.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jammin44fm
        wrote on last edited by
        #3

        Ah yes, of course, thats makes a lot of sense.
        I'll set the item as selected, and change the way i draw a selected item to match that of a hovered item.

        Thank you i think i was trying to overcomplicate things.

        1 Reply Last reply
        0
        • J Jammin44fm has marked this topic as solved on

        • Login

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