Important: Please read the Qt Code of Conduct -

[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]->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()": to return the size you prefer and give it a suitable sizepolicy, you can give it a "fixedSize()": 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);
    QVBoxLayout *layout = new QVBoxLayout(&wid);
    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 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();



Log in to reply