Nominate our 2022 Qt Champions!

QListView selection with mouse

  • Hello again

    I have such question. I painted the QlistView from delegate and there are some items inside listView
    I want to delete the item which I select with mouse. but I don't know if it automatically selects the row in selection model. does it do it? if it does'n how can I do it?

    thank you.

  • Hi!

    I think, like this


  • hi
    I'm doing something like that but I wish to know if mouse click selects in the row inside the model.

  • any row of selectionModel is located in model.

    you can check index if that one is valid if you want

    I don't understand some thing ?

  • tokafr: there is some mouse event click function assigned for handle them on event. Also, there is some flags for tell the QListView if this event has to select the row and how to do it.
    After that, there is also many way of handle them: by press mouse button, or by release the button.
    For exemple, to be able to keep some function allready in place in my QTreeView (like unroll the childs to be shown), i used "mouseReleaseEvent" to handle the click of the mouse.
    Also, consider that you have to write a class who is an implmentation of your QListView for do it (and then, include this function inside).

    After handle the event, this give you back an index (this index is also dependent of the flags configuration give to your QListView options), you can use this index from position at event time handle to do something. if you point on index.row(), so you will act on the row of this index item/model.

    I hope this could help you in what you want to do.

Log in to reply