[PyQt] Problem coding QListWidget

Stephan Hermann sh at sourcecode.de
Tue Dec 16 09:01:02 GMT 2008


Hi Piotr,


On Tue, 2008-12-16 at 09:01 +0100, piotr maliński wrote:
> I'm trying to use QListWidget to make basic file manager. Here:
> http://www.wklej.org/id/28628/ is a example code of a problem that I
> have. If I use mousePressEvent, then SelectionMode doesn't work
> properly (selection range is from top-left corner to cursor position,
> not the area selected by the cursor on mouse pressed), and moving
> items is bit broken (item is not moved to the new cursor position, but
> far far away :)). So the question is - how should I implement events
> for mouse clicks, dragging etc. without making "conflicts" between
> them like with mousePressEvent?
> I need:
> - Right click for item menu ( ?? , mouseReleaseEvent)

This is done like this:

InstanceOfQTreeWidget.setContextMenuPolicy(Qt.CustomContextMenu);

and then connect the SIGNAL("customContextMenuRequested(const QPoint
&)") with your needed popup menu.


> - Left click (single or maybe double) for activating the item (go to
>  directory or open file) ( mouseDoubleClickEvent or ??)

There are already SIGNALS for them...
DoubleClick: SIGNAL("itemDoubleClicked(QTreeWidgetItem *, int)")
SingleClick: SIGNAL("itemClicked(QTreeWidgetItem *, int )")


> - drag & drop to move items to a folder (dropEvent, how to enable
> drops on widget own items?)

I don't know if this helps you, but
http://sector.ynet.sk/qt4-tutorial/dnd.html I find a good pointer.


Regards,

\sh



More information about the PyQt mailing list