How do I upload an image to a graphicsview from a subclass of QGraphicsview
I created new class "TestGV" as a child class of QGraphicsView
I promoted my graphicsView widget on form to "TestGV" class
Where do I create the scene in the mainwindow class or the "TestGV" class
This is what i got, but does not work
definitions in public "TesGv Class"
definitions in public "TesGv Class"
QGraphicsScene *scene;
QGraphicsPixmapItem *newImage;
To copy to clipboard, switch view to plain text mode
//In mainWindow Class -> PushButton "Upload Image"
ui->graphicsView->getImageFileName(); // call function in subclass to get and set image
ui->graphicsView->setScene(ui->graphicsView->scene)
//In mainWindow Class -> PushButton "Upload Image"
ui->graphicsView->getImageFileName(); // call function in subclass to get and set image
ui->graphicsView->scene = new QGraphicsScene(this);
ui->graphicsView->setScene(ui->graphicsView->scene)
To copy to clipboard, switch view to plain text mode
//In subClass "TestGV" "getImageFileName
dialog.setNameFilter(tr("Images (*.png *.jpg *.bmp *)"));
if(dialog.exec())
{
imageFileName1 = dialog.selectedFiles().first();
}
image1.load(imageFileName1);
image1
= image1.
convertToFormat(QImage::Format_RGB32);
QRgb colour;
for (int f1=0; f1<image1.width(); f1++) {
for (int f2=0; f2<image1.height(); f2++) {
colour = image1.pixel(f1, f2);
image1.
setPixel(f1, f2,
QColor((qRed
(colour
) + qGreen
(colour
) + qBlue
(colour
))/3).
rgb());
}
}
pixmap.fromImage(image1);
newImage = scene->addPixmap(pixmap);
//In subClass "TestGV" "getImageFileName
QFileDialog dialog(this, "Upload");
dialog.setNameFilter(tr("Images (*.png *.jpg *.bmp *)"));
dialog.setViewMode(QFileDialog::Detail);
QString imageFileName1;
if(dialog.exec())
{
imageFileName1 = dialog.selectedFiles().first();
}
image1.load(imageFileName1);
image1 = image1.convertToFormat(QImage::Format_RGB32);
QRgb colour;
for (int f1=0; f1<image1.width(); f1++) {
for (int f2=0; f2<image1.height(); f2++) {
colour = image1.pixel(f1, f2);
image1.setPixel(f1, f2, QColor((qRed(colour) + qGreen(colour) + qBlue(colour))/3).rgb());
}
}
QPixmap pixmap;
pixmap.fromImage(image1);
scene = new QGraphicsScene(this);
newImage = scene->addPixmap(pixmap);
To copy to clipboard, switch view to plain text mode
The above code does display Dialogbox & user can select image of choice
But nothing is uploaded
How do I set the scene from the subClass "testGV"
And do the uploading also from "TestGV"
Kindly provide me with example code 
Kind Regards
Bookmarks