<div>Hello,</div><div><br></div><div>I'm trying to create a context menu on right click event and it seems to me that when the code is run on the N900, the context menu is always shows up on the widget BELOW the one that I actually right-clicked on. The same code, however, runs fine on Windows.</div>
<div>Here it is:</div><div><br></div><div>---</div><div><br></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace">import sys</font></font></div><div>
<font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace">from PyQt4.Qt import QApplication, QMainWindow, QWidget, \</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> QVBoxLayout, QListView, QAbstractListModel, \</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> Qt, QVariant, QAbstractListModel, \</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> QEvent, QMenu, QAction,QLabel</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"><br></font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace">class RCListModel(QAbstractListModel):</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"><br></font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> def __init__(self):</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> QAbstractListModel.__init__(self)</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> self.internalList = ["Line 1",</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> "Line 2",</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> "Line 3",</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> "Line 4",</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> "Line 5"]</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"><br></font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> def rowCount(self, parent):</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> return len(self.internalList)</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> def data(self, index, role = Qt.DisplayRole):</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> </font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> if role == Qt.DisplayRole:</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> return self.internalList[index.row()]</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"><br></font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> return QVariant()</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"><br></font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace">class RCListView(QListView):</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> </font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> def __init__(self, parent=None):</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> QListView.__init__(self, parent)</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> self.viewport().installEventFilter(self) </font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> def eventFilter(self, obj, event):</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> '''</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> @param obj QObject</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> @paramn event QEvent</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> ''' </font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> if (event.type() == QEvent.ContextMenu):</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"><br></font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> print event.globalPos()</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"><br></font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> # event is a QMouseEvent</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> menu = QMenu(self)</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> menu.addAction(QAction("Context Menu 1",self))</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> menu.addAction(QAction("Context Menu 2",self))</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> pos = self.viewport().mapToGlobal(event.pos())</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> menu.exec_(pos)</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> return QListView.eventFilter(self, obj, event)</font></font></div><div>
<font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"><br></font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace">class RCMainWindow(QMainWindow):</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> def __init__(self):</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> QMainWindow.__init__(self)</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> widget = QWidget(self)</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> self.setWindowTitle("Right click demo")</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> self.setCentralWidget(widget)</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> self.vbox = QVBoxLayout(widget)</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"><br></font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> self.model = RCListModel()</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> self.listView = RCListView(self)</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> self.listView.setModel(self.model)</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> self.vbox.addWidget(QLabel("My list"))</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> self.vbox.addWidget(self.listView)</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"><br></font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace">class MinimalRightClick:</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> def __init__(self):</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> self.ui = RCMainWindow()</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> self.ui.show()</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace">if __name__ == '__main__':</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> qtApp = QApplication(sys.argv)</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> qtApp.setProperty("FingerScrollBars", False)</font></font></div><div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> app = MinimalRightClick()</font></font></div>
<div><font class="Apple-style-span" color="#999999"><font class="Apple-style-span" face="'courier new', monospace"> sys.exit(qtApp.exec_())</font></font></div><div><br></div><div>---</div><div>Any thoughts?</div>
<div><br></div><div>Thanks,</div><div>Shing</div>