pyqt  

Re: [PyQt] mouse hover, editable, QListview

Zoltan Szalai
Thu, 26 Aug 2010 05:31:27 -0700

 hey,

check the code snippet attached.
it may not perfect but i hope it help you get started.

to keep an editor open you can use the openPersistentEditor method of QAbstractItemView.
http://doc.qt.nokia.com/4.6/qabstractitemview.html#openPersistentEditor


On 2010.08.25. 17:13, M Chauhan wrote:
Dear all,

How can I make an item in a listview editable on mouse hover?

I already tried "AllEditTriggers" but it doesn't work.

Or is there a way to keep item editable by default?

Any suggestion or hints will help.

Kind regards,
Mru

from PyQt4.QtGui import *
from PyQt4.QtCore import *

class ListView(QListView):
    
    def __init__(self, parent=None):
        super(ListView, self).__init__(parent)
        
        self.setMouseTracking(True)
        self.entered.connect(self.onEntered)
    
    def onEntered(self, index):
        if index.isValid():
            self.setCurrentIndex(index)
            self.edit(index, self.AllEditTriggers, None)

if __name__ == '__main__':
    import sys
    import random

    app = QApplication(sys.argv)

    model = QStandardItemModel(10, 1)
    listView = ListView()
    listView.setModel(model)
    
    for row in range(10):
        index = model.index(row, 0, QModelIndex())
        model.setData(index, random.randint(0, 100))

    listView.show()
    sys.exit(app.exec_())
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt