Text selection in model-view implementation



  • Hi, I want to ask if is possible (and how if possible) to make QTreeView's item's text selectable by mouse like when:

    label = QLabel("Selectable text")
    label.setTextInteractionFlags(Qt.TextSelectableByMouse)
    

    I'm using customized QTreeView, QAbstractListModel and QStyledItemDelegate.
    Delegate is painting QTextDocument.

    Not sure if these information are enough.

    Can anyone help me please?



  • I believe (if I am understanding what you mean by selectable) that the fields of a QTreeView are by default selectable and/or editable you would have to explicitly turn that off to stop them from being such.



  • I want to be able to do this kind of selection:
    0_1566545885531_db43cbdf-6714-4267-b355-1671cc501e8a-image.png

    • select text from item and be able to copy selection with shortcut. Like QLabel when you set interaction flag TextSelectableByMouse


  • I describe it incomprehensibly or it's not possible?



  • It required to much research on my part to pursue in the format that it was given and it is not something that I need to do for anything I am working on.

    So you would either need to present it as an MRE (Minimal Reproducible Example) showing how the QLabel works and how that does not work in the QTreeView -- then I can look at that code and determine more easily what it is you are striving to do without having to spend a lot of my time discerning that just to answer your question. Aka you need to do the work to get your question answered not the other way around.


Log in to reply