CPixmapItem
::CPixmapItem(QWidget *parent, Qt
::WFlags flags
){
ui.setupUi( this );
// srand( time( 0 ) );
double width = 1000;
double height = 800;
double worldWidth = 50;
double worldHeight = 4000.0;
mpScene->setSceneRect( 0.0, 0.0, worldWidth, worldHeight );
mpScene->setBackgroundBrush( Qt::lightGray );
mpView->setScene( mpScene );
pRect->setBrush( Qt::white );
mpScene->addItem( pRect );
double rectWidth = pRect->boundingRect().width();
double rectHeight = pRect->boundingRect().height();
long pixWidth = 4;
long pixHeight = 10;
int nItems = 10;
#define RCOLOR ( int( 255 * float( rand() ) / float( RAND_MAX ) ) )
for ( int nItem = 0; nItem < nItems; ++nItem )
{
QColor color
( RCOLOR, RCOLOR, RCOLOR
);
image.fill( color );
double x = rectWidth * double( rand() ) / double( RAND_MAX );
double y = rectHeight * double( rand() ) / double( RAND_MAX );
// pPixMap->setParentItem( pRect );
pPixMap->setOffset( x, y );
// pPixMap->setPos( x, y );
// mpScene->addItem( pPixMap );
}
setCentralWidget( mpView );
resize( long( width ), long( height ) );
mpView->fitInView( pRect->boundingRect() );
}
CPixmapItem::CPixmapItem(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi( this );
// srand( time( 0 ) );
double width = 1000;
double height = 800;
double worldWidth = 50;
double worldHeight = 4000.0;
mpScene = new QGraphicsScene( this );
mpScene->setSceneRect( 0.0, 0.0, worldWidth, worldHeight );
mpScene->setBackgroundBrush( Qt::lightGray );
mpView = new QGraphicsView;
mpView->setScene( mpScene );
QGraphicsRectItem * pRect = new QGraphicsRectItem( 10.0, 100.0, 40.0, 1000.0 );
pRect->setBrush( Qt::white );
mpScene->addItem( pRect );
double rectWidth = pRect->boundingRect().width();
double rectHeight = pRect->boundingRect().height();
long pixWidth = 4;
long pixHeight = 10;
int nItems = 10;
#define RCOLOR ( int( 255 * float( rand() ) / float( RAND_MAX ) ) )
for ( int nItem = 0; nItem < nItems; ++nItem )
{
QImage image( pixWidth, pixHeight, QImage::Format_ARGB32 );
QColor color( RCOLOR, RCOLOR, RCOLOR );
image.fill( color );
QGraphicsPixmapItem * pPixMap = new QGraphicsPixmapItem( QPixmap::fromImage( image ), pRect );
double x = rectWidth * double( rand() ) / double( RAND_MAX );
double y = rectHeight * double( rand() ) / double( RAND_MAX );
// pPixMap->setParentItem( pRect );
pPixMap->setOffset( x, y );
// pPixMap->setPos( x, y );
// mpScene->addItem( pPixMap );
}
setCentralWidget( mpView );
resize( long( width ), long( height ) );
mpView->fitInView( pRect->boundingRect() );
}
To copy to clipboard, switch view to plain text mode
Bookmarks