Qt-interest Archive, November 2007
Displaying and "un"-displaying an image
Message 1 in thread
Hi,
I need some help with displaying a picture via Qt.I have an application
where a user can upload a picture and provide some data to that picture.
When a picture is set the picture will be stored in some configuration
file. To display a picture once the "upload" button is pressed I do
basically the following:
QPixmap myImage;
QGraphicsView *graphicsViewPhoto;
QGraphicsScene *scene = new QGraphicsScene();
QGraphicsPixmapItem *myImage2 = new QGraphicsPixmapItem();
myImage.load(pictureFile) //pictureFile is a QString pointing to the picture
myImage2 -> setPixmap(myImage);
scene -> addItem(myImage2);
graphicsViewPhoto -> setScene(scene);
1. Question
To me it looks a bit cumbersome to have a QPixmap, QGraphicsScene,
QGraphicsPixmapItem and a QGraphicsView object only to display a single
picture. Is there a way more straight forward than my approach?
2. Question
I want to add a "remove" button to remove the picture. When I save my data I
check if there is a photo available via
if(!myImage.isNull()) save_image() ;
So the remove button would need to set the image to a Null image. I couldn't
find a function setNull(). May be it is the wrong way to check for
isNull(), I am open to any suggestion.
Thanks!
--
[ signature omitted ]
Message 2 in thread
On Wednesday 14 November 2007, KH wrote:
> 1. Question
> To me it looks a bit cumbersome to have a QPixmap, QGraphicsScene,
> QGraphicsPixmapItem and a QGraphicsView object only to display a single
> picture. Is there a way more straight forward than my approach?
QLabel can show an image.
> 2. Question
> I want to add a "remove" button to remove the picture. When I save my data
> I check if there is a photo available via
>
> if(!myImage.isNull()) save_image() ;
>
> So the remove button would need to set the image to a Null image. I
> couldn't find a function setNull(). May be it is the wrong way to check for
> isNull(), I am open to any suggestion.
Perhaps remove and delete the item? Or if you use QLabel, call clear() on it.
--
[ signature omitted ]
Message 3 in thread
Jan Ekholm wrote:
> On Wednesday 14 November 2007, KH wrote:
>
>> 1. Question
>> To me it looks a bit cumbersome to have a QPixmap, QGraphicsScene,
>> QGraphicsPixmapItem and a QGraphicsView object only to display a single
>> picture. Is there a way more straight forward than my approach?
>
> QLabel can show an image.
>
>> 2. Question
>> I want to add a "remove" button to remove the picture. When I save my
>> data I check if there is a photo available via
>>
>> if(!myImage.isNull()) save_image() ;
>>
>> So the remove button would need to set the image to a Null image. I
>> couldn't find a function setNull(). May be it is the wrong way to check
>> for isNull(), I am open to any suggestion.
>
> Perhaps remove and delete the item? Or if you use QLabel, call clear() on
> it.
>
QLabel seems to be okay. I just have a problem.
I can use setPixmap() to set an image, the function pixmap() only returns an
invalid pixmap if none is set. So how do I check if a pixmap is set? What
is an "invalid" pixmap?
I've tried to use setPicture() instead since picture() returns 0 if no
picture is set. But QPicture::load() doesn't accept my jpg files. I guess I
have to specify a format within the load() function. But I can't find in
the documentation how this format has to be specified.
Any idea for either way?
Thanks!
--
[ signature omitted ]
Message 4 in thread
KH a écrit :
> I can use setPixmap() to set an image, the function pixmap() only returns an
> invalid pixmap if none is set. So how do I check if a pixmap is set? What
> is an "invalid" pixmap?
>
>
*
The pixmap() method returns a QPixmap pointer or 0 if no pixmap has been
set.
Regards,
*
--
[ signature omitted ]