![]() |
PyQT4: Qlistview - left/right click or long button press
hey there,
I'm wrting a simple gui for a program using eric4, qtdesigner and pyqt4 on maemo. Part of that gui is a Qlistview (http://www.riverbankcomputing.co.uk/...qlistview.html). Qlistview natively support click and doubleclick signals, allowing me to react on these user actions, ie: Code:
clicked ( const QModelIndex & index ) I have already added a custom signal to react on right clicks/contextMenus: Code:
#custom right click event How does one implement "right clicks" correctly without losing the index information and being able to discriminate between the two events? greetings, jinx |
Re: PyQT4: Qlistview - left/right click or long button press
This should translate to "ContextMenu". You need to set a property to enable it and decide how you want to handle it (action menu with default handler, custom slot with signal handler).
|
Re: PyQT4: Qlistview - left/right click or long button press
Hello fpp,
thanks for your answer. I'm not sure I can follow you. I do get the "contextMenu" signal and may also react on it. However, I still do get the *click* signal, since QlistView does not distinguish between left and right click. how do other people achieve having a simple "touch event" and the "press for one second" event? is there a recommended way to do this? greetings, jinx |
Re: PyQT4: Qlistview - left/right click or long button press
hello again,
I think what I need is discrimnate between "tap" and "tap-and-hold". is this possible when dealing with a QListview? greetings, jinx |
Re: PyQT4: Qlistview - left/right click or long button press
I have been able to achieve what I think you are looking for, though I am using a QListWidget, rather than a QListView.
To obtain a context menu following a long press, I first set the contextMenuPolicy: Code:
self.listWidget.setContextMenuPolicy(Qt.ActionsContextMenu) Code:
self.actionEdit = QAction("Edit", self.listWidget) Code:
self.connect(self.actionEdit, SIGNAL("triggered()"), self.testMethod) |
Re: PyQT4: Qlistview - left/right click or long button press
hey marxian,
thanks for your answer. that's good to know, but actually not what I have been looking for. nevertheless I have figured it out in the meantime. For now it's nothing more than an ugly hack though :) what I want/need is the following: Code:
on left click on a list item - do action 1 Code:
on left click: play song luckily, when using the setContextMenu approach, the linked method is always triggered before the clicked signal. So I can set self.right = True in this method. when clicked is called afterwards it determines if self.right is set or not and acts accordingly. this is the ugly solution I ended up with for now. I'm sure I can come up with something better, when I programmed some more QT/PyQT. Code:
#custom right click event Code:
def onRightClick(self): Code:
def on_listView_clicked(self, index): jinx |
All times are GMT. The time now is 03:28. |
vBulletin® Version 3.8.8