Results 1 to 3 of 3

Thread: Problem resizing a QFrame

  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Problem resizing a QFrame

    I've created a window and added a frame to it. The frame would contain some widgets such as LineEdit, ListBox, etc. I would change one frame with another one according to a menu selection. Now my issue is, when I maximize the main window, the frame is not getting expanded according to the new size. I tried to look at a few functions like sizePolicy, etc, but didn't understand though. I've provided the code below.

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QtGui/QMainWindow>
    5. #include <QVBoxLayout>
    6. #include <QFrame>
    7.  
    8. class MainWindow : public QMainWindow
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. MainWindow(QWidget *parent = 0);
    14. ~MainWindow();
    15. void baseLayerSettings(void);
    16.  
    17. private:
    18. QFrame *baseLayer;
    19.  
    20. };
    21.  
    22. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. MainWindow::MainWindow(QWidget *parent)
    4. : QMainWindow(parent)
    5. {
    6. baseLayerSettings();
    7. }
    8.  
    9. MainWindow::~MainWindow()
    10. {
    11.  
    12. }
    13. void MainWindow::baseLayerSettings(void)
    14. {
    15. baseLayer = new QFrame(this);
    16. baseLayer->setGeometry(0, 0, 800, 600);
    17. baseLayer->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
    18. baseLayer->setStyleSheet("background-color: qlineargradient(spread:pad, x1:0.504, y1:1, x2:0.497273, y2:0, stop:0 rgba(51, 142, 220, 255), stop:1 rgba(255, 255, 255, 255))");
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 

    Please help me with this. Thank you.

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Problem resizing a QFrame

    Quote Originally Posted by rawfool View Post
    . . . added a frame to it. . . .
    No, you haven't. Try this:
    Qt Code:
    1. baseLayerSettings();
    2. setCentralWidget(baseLayer);
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to norobro for this useful post:

    rawfool (22nd November 2011)

  4. #3
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Problem resizing a QFrame

    Thank you dude. It worked.

Similar Threads

  1. Qpainter function on a QFrame problem
    By impeteperry in forum Newbie
    Replies: 45
    Last Post: 14th October 2008, 12:43
  2. problem with QFrame isVisible()
    By impeteperry in forum Qt Programming
    Replies: 1
    Last Post: 5th August 2008, 16:29
  3. QFrame problem
    By impeteperry in forum Qt Programming
    Replies: 4
    Last Post: 23rd February 2008, 20:34
  4. resizing down problem
    By MrGarbage in forum Qt Tools
    Replies: 1
    Last Post: 23rd October 2007, 19:37
  5. QTabWidget - problem with resizing
    By moowy in forum Qt Programming
    Replies: 5
    Last Post: 14th September 2006, 14:06

Tags for this Thread

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.