Results 1 to 6 of 6

Thread: Set the image at the center in QLabel?

  1. #1
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Set the image at the center in QLabel?

    Hi ALL,

    I m using Qt 4.1.5 on my MAC.

    I have a dialog in which i m showing the image on a Label and if the image is bigger than there is a scroll area to scroll it.

    But if image is small then it shows it in the Upper left corner of the dialog but I want that the image should start from the center.

    Im using the following code o do it..


    Qt Code:
    1. QLabel *imageLabel = new QLabel(pFilePreviewDlg);
    2. imageLabel->setAlignment (Qt::AlignCenter);
    3. imageLabel->setBackgroundRole(QPalette::Base);
    4. imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    5. imageLabel->setPixmap(pixmap);
    6.  
    7. QScrollArea *scrollArea = new QScrollArea(pFilePreviewDlg);
    8. scrollArea->setBackgroundRole(QPalette::Dark);
    9. scrollArea->setWidget(imageLabel);
    10. scrollArea->setGeometry (2,0,460,490);
    To copy to clipboard, switch view to plain text mode 


    So if any body knows how I can set the image on the center on a dialog then plz help me.

    Thanks.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Set the image at the center in QLabel?

    Qt Code:
    1. imageLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Re: Set the image at the center in QLabel?

    Thanks for reply.

    Actually I have tried this but nothing changes.The image is still not in the center of the dialog.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Set the image at the center in QLabel?

    Use QScrollArea::setAlignment(). And use a layout to place the scrollarea into the dialog instead of hardcoding its geometry.
    J-P Nurmi

  5. #5
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Re: Set the image at the center in QLabel?

    Thanks for reply.

    But I m using Qt 4.1.5 and it does not have that property for QScrollArea.

  6. #6
    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: Set the image at the center in QLabel?

    Call setWidgetResizable(true) on the scroll area.

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

    vishal.chauhan (21st August 2007)

Similar Threads

  1. Explanation to Image Formats
    By sincnarf in forum Qt Programming
    Replies: 13
    Last Post: 6th July 2007, 17:02
  2. Help needed handling image data
    By toratora in forum General Programming
    Replies: 2
    Last Post: 11th May 2007, 09:24
  3. how i can add image in my toolbar
    By jyoti in forum Qt Tools
    Replies: 7
    Last Post: 19th December 2006, 14:39
  4. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36
  5. Question about updating an image on screen
    By SkripT in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2006, 19:01

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.