Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: keepaspectratio problem

  1. #1
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default keepaspectratio problem

    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
    Qt Code:
    1. QImage ImageToLoad;
    2. ImageToLoad.load(dir.absoluteFilePath(dirList.value(localimage)));
    3. QLabel *label = new QLabel(this);
    4. label->setPixmap(QPixmap::fromImage(ImageToLoad.scaled( 1025,1025,Qt::KeepAspectRatio)));
    5. label->show();
    To copy to clipboard, switch view to plain text mode 
    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
    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: keepaspectratio problem

    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,
    _

  3. #3
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: keepaspectratio problem

    when am keeping single label for each images my program has stopped not executing,,as you said now am checking to delete previous label
    Quote Originally Posted by anda_skoa View Post
    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,
    _

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: keepaspectratio problem

    Quote Originally Posted by iswaryasenthilkumar View Post
    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,
    _

  5. #5
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: keepaspectratio problem

    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"

  6. #6
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: keepaspectratio problem

    Quote Originally Posted by iswaryasenthilkumar View Post
    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.

  7. #7
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: keepaspectratio problem

    i getting same error olive
    Qt Code:
    1. The program has unexpectedly finished.
    To copy to clipboard, switch view to plain text mode 
    my code below
    Qt Code:
    1. void Widget::displayimages()
    2. {
    3.  
    4. ImageToLoad.load(dir.absoluteFilePath(dirList.value(localimage)));
    5. label->setPixmap(QPixmap::fromImage(ImageToLoad.scaled( 1025,1025,Qt::KeepAspectRatio)));
    6. label->show();
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 
    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



    Quote Originally Posted by yeye_olive View Post
    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.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: keepaspectratio problem

    Quote Originally Posted by iswaryasenthilkumar View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: keepaspectratio problem

    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
    Quote Originally Posted by wysota View Post
    If you delete the label then it is not valid anymore so if you try to access it afterwards, your program crashes.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: keepaspectratio problem

    Again, reuse an existing label instead of creating a new one for each image.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. The following user says thank you to wysota for this useful post:

    iswaryasenthilkumar (2nd April 2015)

  12. #11
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: keepaspectratio problem

    i cant see the images
    Qt Code:
    1. Widget.h
    2. QLabel *label;
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. widget.cpp
    2. Widget::Widget(QWidget *parent) :
    3. QWidget(parent),
    4. ui(new Ui::Widget)
    5. {
    6. label = new QLabel(this);
    7. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void Widget::displayimages()
    2. {
    3.  
    4. ImageToLoad.load(dir.absoluteFilePath(dirList.value(localimage)));
    5. label->setPixmap(QPixmap::fromImage(ImageToLoad.scaled( 1025,1025,Qt::KeepAspectRatio)));
    6. label->show();
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 
    [/code]
    as you said i reusing the label bt i cant see the images
    Quote Originally Posted by wysota View Post
    Again, reuse an existing label instead of creating a new one for each image.

  13. #12
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: keepaspectratio problem

    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:
    1. a custom widget which would scale, position, and paint the image like I needed;
    2. 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.

  14. #13
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: keepaspectratio problem

    Quote Originally Posted by iswaryasenthilkumar View Post
    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,
    _

  15. #14
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: keepaspectratio problem

    can you give some example i know am doing wrong please give some example how to rectify this problem
    Quote Originally Posted by anda_skoa View Post
    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,
    _

  16. #15
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: keepaspectratio problem

    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,
    _

  17. The following user says thank you to anda_skoa for this useful post:

    iswaryasenthilkumar (2nd April 2015)

  18. #16
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: keepaspectratio problem

    my task is want to create label through code,,and also i rectified the problem,thank you so much
    my code
    Qt Code:
    1. widget.cpp
    2. Widget::Widget(QWidget *parent) :
    3. QWidget(parent),
    4. ui(new Ui::Widget)
    5. {
    6. label = new QLabel;
    7. }
    To copy to clipboard, switch view to plain text mode 
    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
    Quote Originally Posted by anda_skoa View Post
    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,
    _

  19. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: keepaspectratio problem

    Which code?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  20. #18
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: keepaspectratio problem

    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,,??

  21. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: keepaspectratio problem

    Put it in a layout.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  22. The following user says thank you to wysota for this useful post:

    iswaryasenthilkumar (3rd April 2015)

  23. #20
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: keepaspectratio problem

    Quote Originally Posted by iswaryasenthilkumar View Post
    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.

  24. The following user says thank you to yeye_olive for this useful post:

    iswaryasenthilkumar (3rd April 2015)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.