×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    23

    How to resize the Widgets inside the Layout

    Hai everybody,
    This is my code , iam using QTDesigner to done this.
    I have a problem like how to dynamically change the size and positions of Widgets inside the Layouts.
    I tried seteomentry() ,nothing happened.
    Is there any way to achieve this.

    Code:
    class Ui_sampleWidget
    {
    public:
        QVBoxLayout *verticalLayout_5;
        QScrollArea *scrollArea;
        QWidget *scrollAreaWidgetContents;
        QVBoxLayout *verticalLayout_2;
        QLabel *label_3;
        QVBoxLayout *verticalLayout;
        QListView *listView;
        QLabel *label_4;
        QVBoxLayout *verticalLayout_3;
        QListView *listView_2;
    
        void setupUi(QWidget *sampleWidget)
        {
            if (sampleWidget->objectName().isEmpty())
                sampleWidget->setObjectName(QString::fromUtf8("sampleWidget"));
            sampleWidget->resize(240, 170);
            verticalLayout_5 = new QVBoxLayout(sampleWidget);
            verticalLayout_5->setObjectName(QString::fromUtf8("verticalLayout_5"));
            scrollArea = new QScrollArea(sampleWidget);
            scrollArea->setObjectName(QString::fromUtf8("scrollArea"));
            scrollArea->setFrameShape(QFrame::NoFrame);
            scrollArea->setFrameShadow(QFrame::Plain);
            scrollArea->setWidgetResizable(true);
            scrollAreaWidgetContents = new QWidget();
            scrollAreaWidgetContents->setObjectName(QString::fromUtf8("scrollAreaWidgetContents"));
            scrollAreaWidgetContents->setGeometry(QRect(0, 0, 205, 196));
            verticalLayout_2 = new QVBoxLayout(scrollAreaWidgetContents);
            verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
            label_3 = new QLabel(scrollAreaWidgetContents);
            label_3->setObjectName(QString::fromUtf8("label_3"));
            QFont font;
            font.setBold(true);
            font.setWeight(75);
            label_3->setFont(font);
    
            verticalLayout_2->addWidget(label_3);
            verticalLayout = new QVBoxLayout();
            verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
            listView = new QListView(scrollAreaWidgetContents);
            listView->setObjectName(QString::fromUtf8("listView"));
    
            verticalLayout->addWidget(listView);
            verticalLayout_2->addLayout(verticalLayout);
    
            label_4 = new QLabel(scrollAreaWidgetContents);
            label_4->setObjectName(QString::fromUtf8("label_4"));
            label_4->setFont(font);
    
            verticalLayout_2->addWidget(label_4);
            verticalLayout_3 = new QVBoxLayout();
            verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3"));
            listView_2 = new QListView(scrollAreaWidgetContents);
            listView_2->setObjectName(QString::fromUtf8("listView_2"));
    
            verticalLayout_3->addWidget(listView_2);
            verticalLayout_2->addLayout(verticalLayout_3);
            scrollArea->setWidget(scrollAreaWidgetContents);
            verticalLayout_5->addWidget(scrollArea);
            retranslateUi(sampleWidget);
            QMetaObject::connectSlotsByName(sampleWidget);
        } // setupUi
    Thanks for any reply,
    Deepak S

  2. #2
    Super Contributor
    Join Date
    Nov 2004
    Posts
    1,009

    Re: How to resize the Widgets inside the Layout

    Regards,
    Shafali

  3. #3
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to resize the Widgets inside the Layout

    For QVBoxLayout you can set stretch factor to specific layout's cells to control their sizes
    http://doc.trolltech.com/4.7/qboxlayout.html#setStretch
    Other layouts have similar possibilities.

  4. #4
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: How to resize the Widgets inside the Layout

    If you're doing this inside a layout you need to somehow manipulate the "sizeHint". You can set minimum/maximum sizes, or you can reimplement sizeHint and maybe minimumSizeHint. I think in the latter case you need to call updateGeometry after changing your parameters.

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    23

    Re: How to resize the Widgets inside the Layout

    2>>
    Hey guptha thanks for ur reply man , But that link tells about the layouts having only one layout , i Need single layout having multiple widget and resize and repositioning the every widget dynamically .
    That link is really helping me for the other problems.

    3>>
    Thanks for the reply buddy ,I am a newbie to Qt so with that class reference , i cant able to make layouts boss , I dont know where i have to call the strech factor and every thing.
    With out layout i can make the widget resizable .So pls give some small example to resizing the widgets inside the layout.

    4>.
    Thanks for the reply , I have a doubt like if i reimplement the sizeHint means which size will change (layout or widget).
    Pls give sample for this doubt.

  6. #6
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: How to resize the Widgets inside the Layout

    The "sizeHint" of a widget is how the widget communicates to the layout how big it is. The layout interrogates the sizeHint fo each widget before budgeting the available screen space to individual widgets.

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    23

    Re: How to resize the Widgets inside the Layout

    i can understand what u r reply , but.... idont how to implement in my screen , pls give me a sample code like , use my design and change the size of the listview .

  8. #8
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: How to resize the Widgets inside the Layout

    But then I'd be depriving you of the fun and satisfaction of learning all this yourself.

  9. #9
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: How to resize the Widgets inside the Layout

    Small demonstration application
    Code:
    #include <QtGui>
    
    int main (int argc, char **argv)
    {
        QApplication app(argc, argv);
        app.setStyleSheet("#one {background: red} #two {background: green}"
                          "#three {background: blue} #four {background: white}");
    
        QGridLayout *layout = new QGridLayout;
        QLabel *label1 = new QLabel("Label");
        label1->setObjectName("one");
        QLabel *label2 = new QLabel("Label");
        label2->setObjectName("two");
        QLabel *label3 = new QLabel("Label");
        label3->setObjectName("three");
        QLabel *label4 = new QLabel("Label");
        label4->setObjectName("four");
        layout->addWidget(label1, 0, 0, 1, 2);
        layout->addWidget(label2, 1, 0, 2, 1);
        layout->addWidget(label3, 1, 1);
        layout->addWidget(label4, 2, 1);
        layout->setRowStretch(0, 5);
        layout->setRowStretch(1, 10);
        layout->setRowStretch(2, 0);
        layout->setColumnStretch(0, 5);
        layout->setColumnStretch(1, 0);
    
        QWidget w;
        w.setLayout(layout);
        w.show();
    
        return app.exec();
    }

Similar Threads

  1. issue in deleting a layout and setting a new layout..
    By sathyanarayanan.se in forum Qt
    Replies: 8
    Last Post: 2010-10-05, 13:24
  2. Replies: 6
    Last Post: 2010-08-04, 13:33
  3. Replies: 2
    Last Post: 2010-06-02, 11:07
  4. Detecting Keypad Layout and Screen Layout
    By chonada in forum Symbian User Interface
    Replies: 1
    Last Post: 2008-02-01, 03:13

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×