PDA

View Full Version : keepaspectratio problem



iswaryasenthilkumar
1st April 2015, 15:50
am having multiple images each having different aspect ratio am going to display each images one after another for every 10 seconds. the probelm is the images are replacing for every 10 seconds i dont get proper images because images are dfferent in size,and also its showing previous images if current images are small in size i dont get idea to display without replacing.
my codes are below


QImage ImageToLoad;
ImageToLoad.load(dir.absoluteFilePath(dirList.valu e(localimage)));
QLabel *label = new QLabel(this);
label->setPixmap(QPixmap::fromImage(ImageToLoad.scaled( 1025,1025,Qt::KeepAspectRatio)));
label->show();

i need if the previous displayed images are big and if the current images are small while displaying i should not see previous image while current image displaying
Please guide me to rectify this problem:confused::(
Thanks in advance:o

anda_skoa
1st April 2015, 16:26
Your code does not show how you delete the label of the previous image.

Which brings us to the question: why do you have a new label for each image if you want to only show one at a time?

Cheers,
_

iswaryasenthilkumar
2nd April 2015, 07:01
when am keeping single label for each images my program has stopped not executing,,as you said now am checking to delete previous label
Your code does not show how you delete the label of the previous image.

Which brings us to the question: why do you have a new label for each image if you want to only show one at a time?

Cheers,
_

anda_skoa
2nd April 2015, 08:41
when am keeping single label for each images my program has stopped not executing
What does that mean?
That should work without any problem.

Cheers,
_

iswaryasenthilkumar
2nd April 2015, 08:47
i declared Qlabel *label in widget.h ,,i used this label to upload images using pixmap but my program stopped i getting this message
" this program unexpectedly finished"

yeye_olive
2nd April 2015, 10:31
i declared Qlabel *label in widget.h ,,i used this label to upload images using pixmap but my program stopped i getting this message
" this program unexpectedly finished"
The reason for that is most likely completely orthogonal to the choice between 1 or many instances of QLabel. Have you run the code through a debugger? What results did you get? Please post the non-working code.

iswaryasenthilkumar
2nd April 2015, 11:22
i getting same error olive


The program has unexpectedly finished.

my code below


void Widget::displayimages()
{

ImageToLoad.load(dir.absoluteFilePath(dirList.valu e(localimage)));
label->setPixmap(QPixmap::fromImage(ImageToLoad.scaled( 1025,1025,Qt::KeepAspectRatio)));
label->show();

}

as per anda_skoa said i used label->deletelater to delete label while am using in code i cant able to see images.how to delete previous images please give me suggestion for this:(




The reason for that is most likely completely orthogonal to the choice between 1 or many instances of QLabel. Have you run the code through a debugger? What results did you get? Please post the non-working code.

wysota
2nd April 2015, 11:35
as per anda_skoa said i used label->deletelater to delete label while am using in code i cant able to see images.how to delete previous images please give me suggestion for this:(

If you delete the label then it is not valid anymore so if you try to access it afterwards, your program crashes.

iswaryasenthilkumar
2nd April 2015, 11:53
my problem is i can able to see the previous images if current image was small ,i want to display like slideshow as per imagesaspect ratio,i should not see the previous images while current images are displaying
If you delete the label then it is not valid anymore so if you try to access it afterwards, your program crashes.

wysota
2nd April 2015, 12:05
Again, reuse an existing label instead of creating a new one for each image.

iswaryasenthilkumar
2nd April 2015, 12:19
i cant see the images


Widget.h
QLabel *label;



widget.cpp
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
label = new QLabel(this);
}




void Widget::displayimages()
{

ImageToLoad.load(dir.absoluteFilePath(dirList.valu e(localimage)));
label->setPixmap(QPixmap::fromImage(ImageToLoad.scaled( 1025,1025,Qt::KeepAspectRatio)));
label->show();

}

[/code]
as you said i reusing the label bt i cant see the images
Again, reuse an existing label instead of creating a new one for each image.

yeye_olive
2nd April 2015, 12:23
I once solved a similar problem: display images with various aspect ratios centered in a widget, change the image without completely messing up the layout. I vaguely remember -- but I may have overlooked something, and/or the situation might have changed since then -- that QLabel on its own was not the ideal solution. I ended up implementing two perfectly working solutions:

a custom widget which would scale, position, and paint the image like I needed;
a general-purpose layout manager that would scale and position the widgets inside it while respecting their preferred aspect ratio, in which I would put a QLabel displaying the image.

Solution 1 is faster to implement, but also less reusable.

anda_skoa
2nd April 2015, 12:25
i declared Qlabel *label in widget.h ,,i used this label to upload images using pixmap but my program stopped i getting this message
" this program unexpectedly finished"
Are you actually creating an instance for this pointer?
You code snippet in the first posting looks like you are creating a local instance, not using the member.

Cheers,
_

iswaryasenthilkumar
2nd April 2015, 13:06
can you give some example i know am doing wrong please give some example how to rectify this problem
Are you actually creating an instance for this pointer?
You code snippet in the first posting looks like you are creating a local instance, not using the member.

Cheers,
_

anda_skoa
2nd April 2015, 14:07
You latest code snippet looks reasonably OK, though the label is not part of any layout.
Why don't you just add the label in designer instead of adding it later on in code?

Cheers,
_

iswaryasenthilkumar
2nd April 2015, 15:23
my task is want to create label through code,,and also i rectified the problem,thank you so much
my code


widget.cpp
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
label = new QLabel;
}

but some issues in there,,first 3 images are displayed in one label after again new label arrising in that few images displaying in this label i cant able to see my images like slideshow..whats wrong in my code

You latest code snippet looks reasonably OK, though the label is not part of any layout.
Why don't you just add the label in designer instead of adding it later on in code?

Cheers,
_

wysota
2nd April 2015, 15:38
Which code?

iswaryasenthilkumar
3rd April 2015, 11:10
nw my code executing ,,using single label to display multiple images,,but my label was not fit to widget,how to fit my label to widget,,??

wysota
3rd April 2015, 11:22
Put it in a layout.

yeye_olive
3rd April 2015, 11:25
nw my code executing ,,using single label to display multiple images,,but my label was not fit to widget,how to fit my label to widget,,??
That is what layout managers are for. anda_skoa already remarked in this thread that you created QLabel without putting them in layouts.

iswaryasenthilkumar
3rd April 2015, 11:32
k i will use layout,,but my question is, first i created new label for every images its fit to widget,,but when am using single label with multipe images its not fit to window? whats the reason,,i dont the reason can you explain it please

wysota
3rd April 2015, 11:54
whats the reason,,i dont the reason can you explain it please

The reason is in your code which we unfortunately haven't seen so far.