2013-05-02 62 views
0

幫助我有一個上有一個GraphicsView的應用程序,點的負載牽引到的QGraphicsView和分配使用此代碼QRubberBand,如何選擇物品? QT文件根本就不

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

一些數據,我的鼠標事件我有這個

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

而且QList作包含沒事的時候就應該有它的

我的所有項目在看文檔和使用這個我無法找到任何關於選擇如何實際工作有幫助的演示,

任何幫助,將不勝感激乾杯

回答

2

試試這個:

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

確定,但即時通訊相當肯定,這將改變什麼,因爲我不知道如何進行選擇可能,如,什麼是碼所以,當我已經突出顯示我的graphicsView上的點的區域,我已經聲明實際上被填充的項目? – AngryDuck 2013-05-02 10:32:56

+0

當您將拖動模式設置爲QGraphicsView :: RubberBandDrag時,它應該自行處理選擇。在鼠標釋放事件中,您可以像檢查代碼一樣檢查選定的項目。您只需設置拖動模式,並確保您的物品打開了可選標誌。 – thuga 2013-05-02 10:48:50

+0

好吧,所以在釋放我需要'QList selected = ui-> graphicsView-> scene() - > selectedItems();'它應該填充所有的項目? – AngryDuck 2013-05-02 10:56:19