AngryDuck
AngryDuck

Reputation: 4607

QRubberBand, How to select items??? QT Docs do not help at all

I have an application that has a GraphicsView on it, loads of dots are drawn onto the QGraphicsView and assigned some data using this code

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++;
}

on my mouse event i have this

if(event->type() == Qt::RightButton)
    {
        ui->graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
        QList<QGraphicsItem*> selected = ui->graphicsView->scene()->selectedItems();
    }

And the QList contains nothing when it should have all my items in it

looking at docs and demos that use this i cant find anything helpful on how the selection actually works,

any help would be appreciated cheers

Upvotes: 0

Views: 535

Answers (1)

thuga
thuga

Reputation: 12931

Try this:

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

Upvotes: 2

Related Questions