Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Different context menu for Items and QTreeView "background"..
Forum Updated to NodeBB v4.3 + New Features

Different context menu for Items and QTreeView "background"..

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 544 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.
  • T Offline
    T Offline
    tb24dev
    wrote on 27 Jan 2024, 10:32 last edited by tb24dev
    #1

    Hello there! o)

    I've been reading here and everywhere else for some days now, my eyes already hurt from all the "Q"s in those class names o), but I cannot find any decent advice on how to approach the following:

    ec0891f8-8c48-4304-8cb8-9cc4f72e062d-image.png

    I'm evaluating whether PySide6 and the QTreeView allows the illustrated behaviour (using customization of course). Priority is on point 1), being able to detect various mouse button clicks (single, double, right vs. left) next to the items text (into the light green area) and to interpret it as targeting the actual container of all the items or the tree view itself. The dark green area should be no problem to handle as container and "not the item", since nothing in those columns will be treated as item. It might be moe difficult to start a drag-select from there though, but that's a future problem.

    Point 2) the drag select feature as shown is not available by default in Qt it seems, if I cannot get this to work, this is not a show stopper, but it would hurt a bit! o)

    I guess Point 3), the context menu for items (only on their text) and still being able to do 4), the drag'n'drop operations, are less of a problem, if I resolved the other points.

    What approach would you choose to tackle the container / tree view context menu? I already read about using item delegators, editors, indexAt(), .isValid(), different ways of hooking into context menu events, but I could not find out how to detect a click outside of the items text area to mimic a click on the tree views "background".

    Looking at Windows Explorer, it comes very close to what I try to do.

    6b4047a5-639d-43b0-b4ce-eee06ed0ee6a-image.png

    I am the average dev, from VB-Forms, to HTML to WPF, I've seen some things, I hope I get my head around PyQt as well.

    I appreciate any advice, thank you in advance! o)

    ps: The first illustration is from my prototype, using QT Designer, layouts, splitters etc. and populating the tree view with columns and file system names (not using this QFilesystemModell, it seemed to be too slow with 3000+ items, at least with loading and showing file icons, which it does by default). So, only after trying and getting my Qt/Python newbie hands dirty a bit, I dared to ask! o)

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 27 Jan 2024, 20:18 last edited by
      #2

      Hi and welcome to devnet,

      Some stuff that you should go through:

      https://doc.qt.io/qt-6/dnd.html
      https://doc.qt.io/qt-6/model-view-programming.html#using-drag-and-drop-with-item-views

      For the selection, isn't QAbstractItemView::MultiSelection what you are looking for ?

      QMenu is what you are looking for to build your contextual menu.

      To do the custom handling of mouse event, you wil have to re-implement the mouse related functions but don't forget to ensure that you are not breaking the original handling as otherwise the drag and drop and selection will also break.

      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
      0

      1/2

      27 Jan 2024, 10:32

      • Login

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