[Split] setting buttons size



  • hello sigrid

    its working now..u r right enum doesnt cause any problem..thanks for your suggestion..

    now i have one more query to ask you..actually i want to set width and height of a buttons in codding for that i have used following code..
    @for(int i=0;i<5;i++) {
    for(int j=0;j<5;j++) {
    but[i][j]=new QPushButton();
    but[i][j]->setMinimumWidth(68);
    but[i][j]->setMinimumHeight(60);
    but[i][j]->setStyleSheet("background-image: url(:/images/but-active.png);");

    }}@

    here height is set but width is not set..can you please suggest me why..any option to change the height and width of a buttons..similar to the size of image set as bacground image of the buttons

    [EDIT: split off to a new topic, Volker]



  • In the future, can you please post new questions in new threads?

    You can change the size of QPushButtons in different ways. You can reimplement its "sizeHint()":http://doc.qt.nokia.com/4.7/qwidget.html#sizeHint-prop to return the size you prefer and give it a suitable sizepolicy, you can give it a "fixedSize()":http://doc.qt.nokia.com/4.7/qwidget.html#setFixedSize or you can give it a minimum size. Setting a minimum width and minimum height causes the QPushButton to have the requested minimum size for me in the example below. Does my example reproduce the problem you are having? If not, can you modify it so that it does?

    @#include <QtGui>

    int main(int argc, char** argv)
    {
    QApplication app(argc, argv);
    QWidget wid;
    QPushButton *button = new QPushButton(&wid);
    button->setMinimumWidth(68);
    button->setMinimumHeight(60);
    QVBoxLayout *layout = new QVBoxLayout(&wid);
    layout->addWidget(button);
    wid.show();
    return app.exec();
    }

    @



  • hello sigrid

    Actually the problem is that as i set width and height the buttons the layout change..the code i have wrriten is...here if i dont use setMinimumWidth and setMinimumHeight than layout is fine,but on use of that the layout changes..can u please suggest me wgy this happen..

    @QPushButton *cellbut[6][7]
    QGridLayout *controlyt=new QGridLayout();
    QWidget *centralWidget=new QWidget();
    for(int i=0;i<6;i++)
    {
    for(int j=0;j<7;j++)
    {
    cellBut[i][j]=new QPushButton();
    cellBut[i][j]->setMinimumWidth(68);
    cellBut[i][j]->setMinimumHeight(60);
    controlsLayout->addWidget(cellBut[i][j],i,j);
    }
    }
    ui->centralWidget->setLayout(vLayout);
    setCentralWidget(ui->centralWidget);

    ui->centralWidget->layout()->setSizeConstraint(QLayout::SetNoConstraint);
    

    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.