MainWindow
::MainWindow( QWidget * parent, Qt
::WindowFlags flags
){
...
scene->setSceneRect(0, 0, 800, 600);
scene->setBackgroundBrush(Qt::black);
gvView->setScene(scene);
// create the items
createNPoints(10000);
}
/*
* create some points
*/
void MainWindow::createNPoints(int num)
{
for( int i = 0; i < num; i++ )
createPoint();
}
void MainWindow::createPoint()
{
QGraphicsEllipseItem *p
= scene
->addEllipse
(qrand
()%int(scene
->width
()),qrand
()%int(scene
->height
()),
4,
4);
QColor c
(qrand
()%32
*8,qrand
()%32
*8,qrand
()%32
*8);
p->setPen(c);
p->setBrush(c);
p->setZValue(qrand()%256);
pointsList.append(p);
}
/*
This is the slot called when the user clicks the button to show the items
*/
void MainWindow::showPoints(bool yes)
{
for(int i = 0; i < pointsList.count(); i++)
{
if(yes)
pointsList[i]->show();
else
pointsList[i]->hide();
}
}
MainWindow::MainWindow( QWidget * parent, Qt::WindowFlags flags)
: QMainWindow(parent, flags)
{
...
scene = new QGraphicsScene(this);
scene->setSceneRect(0, 0, 800, 600);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
scene->setBackgroundBrush(Qt::black);
gvView->setScene(scene);
// create the items
createNPoints(10000);
}
/*
* create some points
*/
void MainWindow::createNPoints(int num)
{
for( int i = 0; i < num; i++ )
createPoint();
}
void MainWindow::createPoint()
{
QGraphicsEllipseItem *p = scene->addEllipse(qrand()%int(scene->width()),qrand()%int(scene->height()), 4, 4);
QColor c(qrand()%32*8,qrand()%32*8,qrand()%32*8);
p->setPen(c);
p->setBrush(c);
p->setZValue(qrand()%256);
pointsList.append(p);
}
/*
This is the slot called when the user clicks the button to show the items
*/
void MainWindow::showPoints(bool yes)
{
for(int i = 0; i < pointsList.count(); i++)
{
if(yes)
pointsList[i]->show();
else
pointsList[i]->hide();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks