开发者

Image lists in (Py)Qt

I wanna implement some king of Image List (like this one) with drag-n-drop option (when element is dragged out of list and dropped somewhere, it is not removed from the list and when item is dropped into the lis开发者_JAVA百科t, it is added to the bottom of the list). This list should not have its images 'iconified' (like QListWidget), but should have text under (or aside) the respective items (like QListView).

So, the question is: how it could be implemented using PyQt (or just usual Qt - it's not a problem to convert a bunch of code)?


Use the constructor of QListWidgetItem that takes an icon to insert items with icon into your list. i.e

QListWidget list = new QListWidget  ();
QListWidgetItem item =new QListWidgetItem(QIcon("C:\\My.PNG"),"Winter",list);

Then use these methos with your lists

list1->setDragEnabled(true);
list2->setAcceptDrops(true);

Then, implement these methods:

void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event);
void startDrag(Qt::DropActions supportedActions);

Here you can find an example too

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜