[PyQt] QPlainTextEdit not created in a widget through a QAction
Gerardo Gutierrez
muzgash.lists at gmail.com
Sun Jun 6 01:25:13 BST 2010
Hi, I'm writing a frontend for ipython and I've a problem with a context
menu...
The frontend is based on mathematica so it has cells when you can write code
and execute it (not yet implemented)
So the cells are QPlainTextEdits which are embedded in a QWidget:
class Notebook(QtCore.QObject):
def __init__(self,parent):
QtCore.QObject.__init__(self)
self._container=QtGui.QWidget(parent)
self._nb_menu=NbContextMenu(self._container)
...
...
self.connect(self._nb_menu.new_cell,QtCore.SIGNAL("triggered(bool)"),self.new_cell_slot)
self._container.mousePressEvent = self.nb_mouse_click_event
so the last line is for the context menu to popup con right click:
def nb_mouse_click_event(self,event):
if event.button()==QtCore.Qt.RightButton:
self._nb_menu.popup(event.globalPos())
The NbContextMenu class is described here:
class NbContextMenu(QtGui.QMenu):
def __init__(self,parent):
QtGui.QMenu.__init__(self,parent)
self.set_actions()
def set_actions(self):
self.new_cell=QtGui.QAction("new cell",self)
self.addAction(self.new_cell)
The connection showed above calls a slot which calls a function to create a
new cell in the QWidget called _container:
def new_input_cell(self,index=0):
cell=InputCell(self._container)
if index==0:
prev_cell=self._cell_list[len(self._cell_list)-1]
cell.setGeometry(QtCore.QRect(0,prev_cell.pos().y()+prev_cell.height()+5,395,60))
self._cell_list.append(cell)
else:
prev_cell=self._cell_list[index-1]
cell.setGeometry(QtCore.QRect(0,prev_cell.pos().y()+prev_cell.height()+5,395,60))
self._cell_list.insert(index,cell)
cell.index=self._cell_list.index(cell)
self.connect(cell,QtCore.SIGNAL("cell_index"),self.active_cell_signal)
self.connect(cell,QtCore.SIGNAL("blockCountChanged(int)"),self.expand_cell)
The problem is then, that through the QMenu QAction the cells are being
appended but not showed. This doesn't happen if I call the function
new_input_cell from the constructor in the mainwindow class.
You can check the rest of the code at
http://github.com/muzgash/ipython/tree/master/IPython/gui/qt/
Thanks for your help in advance
Best regards.
--
Gerardo Gutiérrez Gutiérrez <http://he1.udea.edu.co/gweb>
Physics student
Universidad de Antioquia
Computational physics and astrophysics group
(FACom<http://urania.udea.edu.co/sites/sites.php>
)
Computational science and development
branch(FACom-dev<http://urania.udea.edu.co/sites/facom-dev/>
)
Usuario Linux #492295
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100605/69b3e1cf/attachment.html>
More information about the PyQt
mailing list