qDeleteAll(item.begin(), item.end()); item.clear();
bool QGraphicsItem::collidesWithItem ( const QGraphicsItem * other, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape ) const [virtual]
if(item[15]->collidesWithItem(line_3)) {item[15]->setRect(QRectF(-225.0, 160.0, 190.0, 25.0));}
if(item[15]->collidesWithItem(item[13])) {item[15]->setRect(QRectF(-225.0, 160.0, 190.0, 25.0));}
connect(pushButton,SIGNAL(clicked()),this,SLOT(Move()));
void MainWindowImpl::Move(){ item[15]->setRect(QRectF(-225.0, 160.0, 190.0, 25.0));}
#include "mainwindowimpl.h"#include <QGraphicsRectItem>//QList<QGraphicsRectItem *>item;MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f) : QMainWindow(parent, f){ setupUi(this); QGraphicsScene * scene = new QGraphicsScene; scene->setSceneRect(QRectF(-500,-500,1000,1000)); graphicsView->setScene(scene); QGraphicsLineItem *line[6]; int i; for (int i = 1; i < 17; i++) { item.append(new QGraphicsRectItem()); } for (i = 1; i < 7; i++) { line[i] = new QGraphicsLineItem(); } line[1]->setLine(-330, 260, -330.0, -170.0);line[2]->setLine(-450, 260, -210.0, 260.0); line[3]->setLine(-60, 260, -60.0, -170.0);line[4]->setLine(-180, 260, 60.0, 260.0); line[5]->setLine(240, 260, 240.0, -170.0);line[6]->setLine(90, 260, 360.0, 260.0); for(i=1;i<7;i++) {scene->addItem(line[i]);} for (i=1;i<16;i++) {item[i]->setRect(QRectF(-425.0+5*i, 260.0-25*i, 190.0-10*i, 25.0)); scene->addItem(item[i]);} item[15]->setFlag(QGraphicsItem::ItemIsMovable, true); item[13]->setFlag(QGraphicsItem::ItemIsMovable, true); if(item[15]->collidesWithItem(item[13])) {item[15]->setRect(QRectF(-225.0, 160.0, 190.0, 25.0));} connect(pushButton,SIGNAL(clicked()),this,SLOT(Move())); connect(pushButton_2,SIGNAL(clicked()),this,SLOT(Delete()));}void MainWindowImpl::Move(){ item[15]->setRect(QRectF(-225.0, 160.0, 190.0, 25.0));}void MainWindowImpl::Delete(){ qDeleteAll(item.begin(), item.end()); item.clear();}
QGraphicsLineItem *line[6]; int i; for (i = 1; i < 7; i++) { line[i] = new QGraphicsLineItem(); }