C++ QRubberBand,如何选择项目???QT文档根本没有帮助

C++ QRubberBand,如何选择项目???QT文档根本没有帮助,c++,qt,C++,Qt,我有一个应用程序,上面有一个GraphicsView,在QGraphicsView上绘制大量的点,并使用此代码分配一些数据 void GUI::paintitem(double x, double y, double Id) { // Decalre a QPen for Painting dots QPen pen; // set the pen colour pen.setColor(Qt::white); QGraphicsEllipseIte

我有一个应用程序,上面有一个GraphicsView,在QGraphicsView上绘制大量的点,并使用此代码分配一些数据

void GUI::paintitem(double x, double y, double Id)
{

    // Decalre a QPen for Painting dots
    QPen pen;

    // set the pen colour
    pen.setColor(Qt::white);

    QGraphicsEllipseItem *item = new QGraphicsEllipseItem;
    item->setPen(pen);
    item->setBrush(QBrush(Qt::SolidPattern));
    item->setRect(x,y,1.5,1.5);
    item->setData(m_count, Id);
    item->ItemIsSelectable;


    if(x < m_height && y < m_width)
    {
        // Add ellipse at the x y position passed in
        scene2->addItem(item);
    }
    m_count++;
}
void GUI::paintitem(双x、双y、双Id)
{
//用于绘制圆点的贴花
QPen笔;
//设置笔的颜色
钢笔颜色(Qt::白色);
QGraphicsSellipseitem*项=新的QGraphicsSellipseitem;
项目->设置笔(笔);
项目->退刀(QBrush(Qt::SolidPattern));
item->setRect(x,y,1.5,1.5);
项目->设置数据(m_计数,Id);
项目->项目可选择;
if(x附加项(项目);
}
m_count++;
}
在我的鼠标事件中,我有这个

if(event->type() == Qt::RightButton)
    {
        ui->graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
        QList<QGraphicsItem*> selected = ui->graphicsView->scene()->selectedItems();
    }
if(事件->类型()==Qt::RightButton)
{
ui->graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
QList selected=ui->graphicsView->scene()->selectedItems();
}
当QList应该包含所有我的项目时,它不包含任何内容

查看使用此选项的文档和演示,我找不到任何有助于说明选项实际如何工作的内容

任何帮助都将不胜感激。干杯

试试这个:

item->setFlag(QGraphicsItem::ItemIsSelectable, true);

好的,但我很确定这不会改变什么,因为我不知道如何让选择成为可能,比如,代码是什么?当我高亮显示图形视图上的点区域时,我声明的列表实际上会被项目填充?当您将拖动模式设置为QGraphicsView::RubberBandDrag时,它应该自行处理选择。在鼠标释放事件中,您可以像在代码中一样检查所选项目。您需要做的就是设置拖动模式,并确保您的项目已打开可选标志。好的,所以在发布时,我需要选择
QList=ui->graphicsView->scene()->selectedItems()并且应该用所有项目填充?是。在鼠标按下事件中,您将拖动模式设置为QGraphicsView::RubberBandDrag.ok,这似乎有效,因为我对它进行了“.isEmpty”检查,似乎它已填充,您可以看到这些项是如何包含数据的,我现在如何从QList中提取数据,现在它已填充?