Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, January 2007
QGridLayout - newbie question


Message 1 in thread

Hello All,

I am running into problems layouting widgets in QMainWindow. I basically want to set the width of the column in every QGridLayout cell to a particular size. So that when I add a widget to the cell the size of the widget takes on the size of the cell. The problem I am having right now is that the widget appears much bigger than I desire. Here is my MainWindow constructor code -

MainWindow::MainWindow()
{
    QWidget *w = new QWidget;
    setCentralWidget(w);
    w->setFixedSize(800, 600); 
    
    QGridLayout *processbarLayout = new QGridLayout;
 
    processbarLayout->setColumnMinimumWidth(0, 20);//this doesn't seem to work
    processbarLayout->setColumnStretch(0, 20);//this doesn't seem to work
    QPushButton* process1 = new QPushButton;
    processbarLayout->addWidget(process1, 0, 0);

    processbarLayout->setColumnMinimumWidth(1, 20);//this doesn't seem to work
    processbarLayout->setColumnStretch(1, 20);//this doesn't seem to work
    QPushButton* process2 = new QPushButton;
    processbarLayout->addWidget(process2, 0, 1);
 
   w->setLayout(processbarLayout);

}

With this code I get 2 buttons which are centered in the MainWindow widget. Again, I am trying to fix the size of each cell in my QGridLayout so the buttons take on a fix size an not a size dependent on the MainWindow size.

Thanks,
Rog




 
____________________________________________________________________________________
No need to miss a message. Get email on-the-go 
with Yahoo! Mail for Mobile. Get started.
http://mobile.yahoo.com/mail 

Message 2 in thread

Hello All,

I am running into problems layouting widgets in QMainWindow. I basically want to set the width of the column in every QGridLayout cell to a particular size so that when I add a widget to the cell the size of the widget takes on the size of the cell. The problem I am having right now is that the widget appears much bigger than I desire. Here is my MainWindow constructor code -

MainWindow::MainWindow()
{
    QWidget *w = new QWidget;
    setCentralWidget(w);
    w->setFixedSize(800, 600); 
    
    //I am trying to add two buttons to my grid
    QGridLayout *processbarLayout = new QGridLayout;
 
    processbarLayout->setColumnMinimumWidth(0, 20);//this doesn't seem to work, I changed the col. width but it did not make any diff.
   
 processbarLayout->setColumnStretch(0, 20);
    QPushButton* process1 = new QPushButton;
    processbarLayout->addWidget(process1, 0, 0);

    processbarLayout->setColumnMinimumWidth(1, 20);
    processbarLayout->setColumnStretch(1, 20);
    QPushButton* process2 = new QPushButton;
    processbarLayout->addWidget(process2, 0, 1);
 
   w->setLayout(processbarLayout);

}

With this code I get 2 buttons which are centered in the MainWindow and not the correct size. Again, I am trying to fix the size of each cell in my QGridLayout so the buttons take on a fix size an not a size dependent on the MainWindow size.

Thanks,
Rog





Food fight? Enjoy some healthy debate
in the Yahoo! Answers Food & Drink Q&A.





 
____________________________________________________________________________________
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.
http://autos.yahoo.com/new_cars.html 

Message 3 in thread

Hello,

did you take a look at http://doc.trolltech.com/4.2/layout.html (
assuming that you use Qt4.2)? IMHO, you have to take a different
approach. Size the children until they match your desired size and add
them to the layout after that.
It is all described at doc.trolltech.com .

Regards, Clemens


roger t wrote:
> Hello All,
>
> I am running into problems layouting widgets in QMainWindow. I
> basically want to set the width of the column in every QGridLayout
> cell to a particular size so that when I add a widget to the cell the
> size of the widget takes on the size of the cell. The problem I am
> having right now is that the widget appears much bigger than I desire.
> Here is my MainWindow constructor code -
>
> MainWindow::MainWindow()
> {
>     QWidget *w = new QWidget;
>     setCentralWidget(w);
>     w->setFixedSize(800, 600);
>   
>     //I am trying to add two buttons to my grid
>     QGridLayout *processbarLayout = new QGridLayout;
>  
>     processbarLayout->setColumnMinimumWidth(0, 20);//this doesn't seem
> to work, I changed the col. width but it did not make any diff.
>     processbarLayout->setColumnStretch(0, 20);
>     QPushButton* process1 = new QPushButton;
>     processbarLayout->addWidget(process1, 0, 0);
>
>     processbarLayout->setColumnMinimumWidth(1, 20);
>     processbarLayout->setColumnStretch(1, 20);
>     QPushButton* process2 = new QPushButton;
>     processbarLayout->addWidget(process2, 0, 1);
>  
>    w->setLayout(processbarLayout);
>
> }
>
> With this code I get 2 buttons which are centered in the MainWindow
> and not the correct size. Again, I am trying to fix the size of each
> cell in my QGridLayout so the buttons take on a fix size an not a size
> dependent on the MainWindow size.
>
> Thanks,
> Rog
>
>
> ------------------------------------------------------------------------
> Food fight?
> <http://answers.yahoo.com/dir/index;_ylc=X3oDMTFvbGNhMGE3BF9TAzM5NjU0NTEwOARfcwMzOTY1NDUxMDMEc2VjA21haWxfdGFnbGluZQRzbGsDbWFpbF90YWcx?link=ask&sid=396545367>
> Enjoy some healthy debate
> in the Yahoo! Answers Food & Drink Q&A.
> <http://answers.yahoo.com/dir/index;_ylc=X3oDMTFvbGNhMGE3BF9TAzM5NjU0NTEwOARfcwMzOTY1NDUxMDMEc2VjA21haWxfdGFnbGluZQRzbGsDbWFpbF90YWcx?link=ask&sid=396545367>
>
>
> ------------------------------------------------------------------------
> Now that's room service! Choose from over 150,000 hotels
> in 45,000 destinations on Yahoo! Travel
> <http://travel.yahoo.com/hotelsearchpage;_ylc=X3oDMTFtaTIzNXVjBF9TAzk3NDA3NTg5BF9zAzI3MTk0ODEEcG9zAzIEc2VjA21haWx0YWdsaW5lBHNsawNxMS0wNw-->
> to find your fit.

--
 [ signature omitted ]