Results 1 to 10 of 10

Thread: Resize a Widget

  1. #1
    Join Date
    Oct 2007
    Posts
    9
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question Resize a Widget

    Hello Everyone ,
    I want to display a .jpg file in a child widget through QHboxLayOut class in a parent widget.
    but it is not helping me. I mean it does not resize according to given Geometry......
    My code is as follows........
    QLabel *imageLabel;
    imageLabel = new QLabel;
    imageLabel->setBackgroundRole(QPalette::Base);
    imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);

    imageLabel->setScaledContents(true);
    QImage image(mediaPath[currentIndex]);
    imageLabel->setPixmap(QPixmap::fromImage(image));
    QHBoxLayout *layout = new QHBoxLayout(parentWidget);
    layout->addWidget(imageLabel);
    parentWidget->setLayout(layout);
    If anyone has any idea about it please give reply
    Thanks.

  2. #2
    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: Resize a Widget

    Is the parentWidget a window or in a layout?
    J-P Nurmi

  3. #3
    Join Date
    Oct 2007
    Posts
    9
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Lightbulb Re: Resize a Widget

    No Sir , the parent Widget is not a window .
    It is also widget and a child of another QHboxlayOut Object.
    Last edited by sonu; 27th October 2007 at 12:53. Reason: It is also widget and a child of another QHboxlayOut Object.

  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: Resize a Widget

    Quote Originally Posted by sonu View Post
    No Sir , the parent Widget is not a window .
    It is also widget and a child of another QHboxlayOut Object.
    And is this layout installed on a widget? You must have a hierarchy of layouts up to the top level widget, aka window.
    J-P Nurmi

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Resize a Widget

    It would be helpful if you post a minimal compilable piece of code, highlighting the problem, as far as it is possible to rip that part out of the program and still reproduce the same result. Otherwise give us at least the class where the above code is defined.

  6. #6
    Join Date
    Oct 2007
    Posts
    9
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Resize a Widget

    Sir i can't understand your reply .please explain it clearly.

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Resize a Widget

    It's hard to draw conclusions without seeing more code.
    I am still having difficulty to understand what exactly is not working for you.

    Try out this code. Does that work for you?
    Qt Code:
    1. #include <QApplication>
    2. #include <QtGui>
    3.  
    4. int main(int argc, char* argv[])
    5. {
    6. QApplication app(argc, argv);
    7.  
    8. // Image Label
    9. QLabel* imageLabel = new QLabel;
    10. imageLabel->setBackgroundRole(QPalette::Base);
    11. imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    12. imageLabel->setScaledContents(true);
    13.  
    14. // Loading Image
    15. QString fileName = QFileDialog::getOpenFileName(0,
    16. QObject::tr("Open image"),
    17. QApplication::applicationDirPath(),
    18. QObject::tr("Images (*.jpg *.png *.gif *.xpm)"));
    19. imageLabel->setPixmap(fileName);
    20.  
    21. // CentralWidget
    22. QWidget* cw = new QWidget;
    23.  
    24. // Layout
    25. lo->addWidget(imageLabel);
    26. cw->setLayout(lo);
    27.  
    28. // Instantiating and showing mainwindow
    29. mw.setCentralWidget(cw);
    30. mw.show();
    31. return app.exec();
    32. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by momesana; 28th October 2007 at 07:38.

  8. #8
    Join Date
    Oct 2007
    Posts
    9
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Resize a Widget

    Thanks Sir , But my problem is that i can't resize layout widget .
    I mean that i m using hierarchy of layouts . and in the child widget of Parent layout also contain another layout And I want to resize this layout .
    If you can do something ,give reply
    thanks for your suggestion ..........

  9. #9
    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: Resize a Widget

    Could you clearly state what you want? Keep in mind that we don't know anything about your project.
    Quote Originally Posted by sonu View Post
    Thanks Sir , But my problem is that i can't resize layout widget .
    I mean that i m using hierarchy of layouts . and in the child widget of Parent layout also contain another layout And I want to resize this layout
    Well, actually you don't resize by hand anything that is managed by a layout manager. It is layout managers responsibility to maintain geometries of widgets added to it. There are a few ways (size policies, stretch factors..) to fine tune how this is done. Recommended reading: Layout Classes.
    J-P Nurmi

  10. #10
    Join Date
    Oct 2007
    Posts
    9
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Wink Re: Resize a Widget

    Quote Originally Posted by jpn View Post
    Could you clearly state what you want? Keep in mind that we don't know anything about your project.

    Well, actually you don't resize by hand anything that is managed by a layout manager. It is layout managers responsibility to maintain geometries of widgets added to it. There are a few ways (size policies, stretch factors..) to fine tune how this is done. Recommended reading: Layout Classes.
    Sir, I m trying this but it is not helpful.
    Sir in actual i have a parent widget which contain a HBoxLayout with three child widget. Now I m adjust another QHBoxLayout in one of this child widget. But it does not resize acc. to given Geometry.
    So please if u have any idea about it give reply....
    thanks.........

Similar Threads

  1. Controlling which widget on top layer?
    By JonathanForQT4 in forum Qt Programming
    Replies: 6
    Last Post: 22nd March 2007, 14:27
  2. Custom Shape Widget (resize)
    By PiXeL16 in forum Qt Programming
    Replies: 7
    Last Post: 12th February 2007, 07:00
  3. Pin/Unpin Dock Widget
    By charlesD in forum Newbie
    Replies: 1
    Last Post: 21st June 2006, 06:57
  4. postponing resize event
    By Honestmath in forum Qt Programming
    Replies: 11
    Last Post: 26th February 2006, 00:32
  5. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 14:16

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.