Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何移动QListWidgetItem?_C++_Qt_Qlistwidget - Fatal编程技术网

C++ 如何移动QListWidgetItem?

C++ 如何移动QListWidgetItem?,c++,qt,qlistwidget,C++,Qt,Qlistwidget,如何移动QListWidgetItem和不错过Item小部件 这在拖放时有效,但不能在按钮上执行相同的操作 removeItemWidget( item(row) ); QCoreApplication::removePostedEvents (p_widget,QEvent::DeferredDelete ); 我删除了项目中显示的小部件,并以从队列中删除删除信号的方式制作了一个补丁。通过这种方式,我可以将小部件移动到另一个项目 int DropList::moveWidget(int ro

如何移动
QListWidgetItem
和不错过Item小部件

这在拖放时有效,但不能在按钮上执行相同的操作

removeItemWidget( item(row) );
QCoreApplication::removePostedEvents (p_widget,QEvent::DeferredDelete );
我删除了项目中显示的小部件,并以从队列中删除删除信号的方式制作了一个补丁。通过这种方式,我可以将小部件移动到另一个项目

int DropList::moveWidget(int row, int pos)
{
    const int new_row  = row+pos;
    if(count()>1 && row>=0 && row <count() && new_row>=0 && new_row<count())
    {
        // A->B
        DropListItem *pA = widgetByRow(row);
        DropListItem *pB = widgetByRow(new_row);
        if(pB->isMovable() && pA->isMovable())
        {

            removeItemWidget(item(new_row));
            removeItemWidget(item(row));
            QCoreApplication::removePostedEvents (pB,QEvent::DeferredDelete );
            QCoreApplication::removePostedEvents (pA,QEvent::DeferredDelete );
            setItemWidget(item(new_row),pA);
            setItemWidget(item(row),pB);
        }
        emit changed();
        return new_row;
    }
    return 0;
}
int-DropList::moveWidget(int行,int-pos)
{
const int new_row=行+位置;
如果(count()>1&&row>=0&&row=0&&new\u rowB
DropListItem*pA=widgetByRow(行);
DropListItem*pB=widgetByRow(新行);
如果(pB->isMovable()&&pA->isMovable())
{
removeItemWidget(项目(新行));
removeItemWidget(项目(行));
QCoreApplication::removePostedEvents(pB,QEvent::DeferredElete);
QCoreApplication::removePostedEvents(pA、QEvent::DeferredElete);
setItemWidget(项目(新的_行),pA);
setItemWidget(项目(行),pB);
}
发射改变();
返回新的_行;
}
返回0;
}

参数是行-是一个项目位置+1,+2,-1,…。

移动是什么意思?如列表中的上下?缺少项目小部件是什么意思?据我所知,他可以通过拖放移动项目,但他也希望通过按下按钮来移动项目。但我不确定。是的我没有找到任何机制如何使用item小部件上下移动QListWidgetItem。