Selectable Text from QListView



  • Hey could someone pls point me as to what are all the things we need to handle to be able to select text off a QListView which uses a CustomDelegate.

    QListView item contains Text from a QTextDocument and couple other text and image fields.

    Is there any examples or references to use for this requirement.

    If we were to handle mousepress, mousemove and mouserelease, to know the selection area, how do we handle selecting different parts of a QlistView item (changing background color)

    Shld this be done via the delegate's editorEvent and then repainting selected text with different color and sorts.

    Also how would we be able to select Text whose mouse selection spans multiple items of the model or say if we need to scroll the view to show more items since the current mouse selection has reached the bottom of the view's viewport.

    Cant seem to find any answers through google since all posts lead me to "Selecting Entire Items in a ListView" via its index or something and im not looking for that.

    Just looking to get functionality of say something like a chat client modelled with a ReadOnly QListView and have Highlight and Selectable Areas.



  • Just bumping the post up to hope someone can suggest a solution for this.

    Havent still been able to figure out a way to implement text selection in listview items or make them span across multiple items in the view.

    If anyone has any pointers even a small hint, would be very helpful. Thanks

    Sorry about bumping the post. Just cant see another way of getting the thread some attention.



  • Hi,

    Can u attach an image of your listView/form explaining the above requirements regarding selection of different parts of a listView item and others. Thanks .



  • Sure,

    here ya go "Image":http://img84.imageshack.us/img84/4474/chatselection.png

    Example for this would be say any chat client.

    I have each message of this Chat client in a listview item. My question is how do i make it selectable like shown in the picture.



  • Found another example for the same.

    "Kadu":http://img690.imageshack.us/img690/192/chatmc.png

    This I found in the QT Apps actually. seems it is possible just cant seem to figure out how it is done even in this application. Tried going through the source but not able to find exactly what allows his items painted via delegates to be selectable.

    Maybe you guys can identify the section?



  • Hi,
    Did you get any result? I also tried to get some examples . But there i found that mostly QTextEdit is used instead of QListView for a chat application.



  • Nah nothing yet,

    been checking this quite madly actually :)

    Yeh textEdit wouldnt cut my requirement cos the current implementation say has chat messages that can contain buttons and stuff for eg (sending / receiving files)

    Would probably need the editor of the delegate to draw a textEdit for each item where the text can be selected and use mousePositions from the View->Viewport to indicate to the delegate if the mouse was already selected when entering the current item to continue selection.

    Just seems like a really long winded and not proper way to achieve what would be needed



  • Just to update on this.

    I got selectable text sorted however I let go of the entire QListView scenario.

    Went with a QWebView and using the DOM model as a substitute for the QListModel, I could generate QWebElements as desired and you can have interactive buttons and sorts as well via html / javascript and style them using CSS

    As a QWebPage getting content selected is a dolly and this got my requirement satisfied.

    If anyone has a similar requirement. Do Not Go With QListView.

    Main Issue with QListView was even if you design editor widgets that would allow text selection and open these as persistentIndexes,

    we still have problems when the selection goes from one widget to another as the first widget has mouseGrabbed and the second QModelIndex does not receive a MouseEnter event (while the left mouse button is pressed)

    If you manage to release mouse based on the cusor position and on leaving widget, you still got to track which direction mouse enters the new widget to simulate a text selection on its child widgets.

    On the whole, getting this sort of functionality could be possible from a QListView but not something that can be done without subclassing the entire world and managing every action which is not very efficient at all.

    Just pick QWebView or something else that can give this functionality easier :)



  • This problem has just pop up in my work and I found your post.

    My requirements are, in some way, simpler than yours. I just have to select the text from a QListView in the same way QLabel do. Do have any other insights about accomplishing this with QListView?



  • This problem has just pop up in my work and I found your post.

    My requirements are, in some way, simpler than yours. I just have to select the text from a QListView in the same way QLabel do. Do have any other insights about accomplishing this with QListView?



  • Up ! Anybody ! Help =)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.