MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
image->fill(Qt::cyan);
ui->retranslateUi(this);
ui->graphicsView->setScene(scene);
ui->graphicsView->show();
QPen(Qt
::red,
6, Qt
::DashLine, Qt
::FlatCap));
scene
->setBackgroundBrush
(QBrush(Qt
::green, Qt
::SolidPattern));
scene->addEllipse(40, 80, 300, 240,
QPen(Qt
::blue,
10, Qt
::DashDotDotLine, Qt
::RoundCap));
scene->addPixmap(item->pixmap());
// Connect the pushbutton to the buttonPressed method, below.
connect( ui->pushButton, SIGNAL(pressed()),
this, SLOT( buttonPressed() ) );
}
// Slot connected to the button being pressed.
// Manipulate some pixels, and show the results.
void MainWindow::buttonPressed()
{
printf("Now in buttonPressed...\n");
int x, y;
int offset = qrand();
QRgb px;
px = qRgb(20+offset, 10-offset, 30+offset);
for (x=0; x< 60; x++)
for(y=0; y< 60; y++)
{
image->setPixel(x, y, px );
}
// I'd like to NOT have to re-convert the image every time.
scene->addPixmap(item->pixmap());
}
QGraphicsScene *scene = NULL;
QGraphicsItem *line = NULL;
QImage *image = NULL;
QGraphicsPixmapItem *item = NULL;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene = new QGraphicsScene();
image = new QImage(60, 60, QImage::Format_RGB888 );
image->fill(Qt::cyan);
ui->retranslateUi(this);
ui->graphicsView->setScene(scene);
ui->graphicsView->show();
line = (QGraphicsItem*) scene->addLine( QLine( 20, 40, 300, 100 ),
QPen(Qt::red, 6, Qt::DashLine, Qt::FlatCap));
scene->setBackgroundBrush(QBrush(Qt::green, Qt::SolidPattern));
scene->addEllipse(40, 80, 300, 240,
QPen(Qt::blue, 10, Qt::DashDotDotLine, Qt::RoundCap));
item = new QGraphicsPixmapItem(QPixmap::fromImage(*image));
scene->addPixmap(item->pixmap());
// Connect the pushbutton to the buttonPressed method, below.
connect( ui->pushButton, SIGNAL(pressed()),
this, SLOT( buttonPressed() ) );
}
// Slot connected to the button being pressed.
// Manipulate some pixels, and show the results.
void MainWindow::buttonPressed()
{
printf("Now in buttonPressed...\n");
int x, y;
int offset = qrand();
QRgb px;
px = qRgb(20+offset, 10-offset, 30+offset);
for (x=0; x< 60; x++)
for(y=0; y< 60; y++)
{
image->setPixel(x, y, px );
}
// I'd like to NOT have to re-convert the image every time.
item = new QGraphicsPixmapItem(QPixmap::fromImage(*image));
scene->addPixmap(item->pixmap());
}
To copy to clipboard, switch view to plain text mode
Bookmarks