[PyQt] Using drag+drop in a QComboBox

Chris Beaumont beaumont at hawaii.edu
Tue Oct 30 18:54:40 GMT 2012

Fair enough. My application is a window that displays one of several images
for scientific image analysis. A combo box selects which image is
displayed. It's a nice feature that you can "blink" back and forth between
two images with adjacent entries in the combo box by hitting up/down while
the box has keyboard focus. If the items were movable, the user could set
up this blinking feature for any two images, even if they were not
initially adjacent in the combo box.

However, even if I chose a more "traditional" drag+drop widget (say a
QListView), the same thing happens (see code below). The problem seems to
be that you can drop items both on top of existing rows or between rows.
Dropping on top of rows deletes the dragged item. Is this the correct
behavior? Is there a way to restrict drops on list views to be between
items only?


from PyQt4.QtGui import (QApplication, QAbstractItemView,
                         QStandardItemModel, QListView, QStandardItem)

a = QApplication([''])

m = QStandardItemModel()

lv = QListView()


On Tue, Oct 30, 2012 at 2:29 PM, Andreas Pakulat <apaku at gmx.de> wrote:

> Hi,
> On Tue, Oct 30, 2012 at 5:50 PM, Chris Beaumont <beaumont at hawaii.edu>
> wrote:
> > I'm having some trouble getting drag+drop to work properly within a
> > QComboBox widget. I've posted to SO:
> >
> http://stackoverflow.com/questions/13141143/pyqt4-items-disappear-when-using-drag-and-drop-with-qcombobox
> >
> > I thought I'd try here as well. In short, I want to be able to rearrange
> > entries in a QComboBox with the mouse, but
> > the dragged items keep disappearing instead of moving. My code is pasted
> > below. Is there anything obviously wrong here?
> Personally I'd say you're simply using the wrong widget. A combobox is
> for most people a small widget that allows to select an entry from a
> list by having a popup opened and closed automatically. In particular
> I wouldn't be surprised if dragging an item off the open popup would
> immediately close it on some platforms. Not to mention that such a
> behaviour in a combobox is surprising and not very discoverable for
> most users since its not something thats commonly used.
> So can you explain why you need the items to be re-arrangable inside a
> combobox?
> Andreas

Chris Beaumont
Graduate Student
Institute for Astronomy
University of Hawaii at Manoa
2680 Woodlawn Drive
Honolulu, HI 96822
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20121030/b55609c0/attachment.html>

More information about the PyQt mailing list