[Qt-interest] QPushButton width problems / layout issues
John McClurkin
jwm at nei.nih.gov
Thu Jun 24 15:00:24 CEST 2010
Kustaa Nyholm wrote:
>> Have you tried using QSpacerItems in the layout?
>
>
> Yes, here is the code I have:
>
>
>
>
>
> QHBoxLayout *horizontalLayout;
> QPushButton *pushButton;
> QSpacerItem *horizontalSpacer;
> QPushButton *pushButton_2;
>
> horizontalLayout = new QHBoxLayout(this);
> horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
> pushButton = new QPushButton("A", this);
> pushButton->setObjectName(QString::fromUtf8("pushButton"));
>
> horizontalLayout->addWidget(pushButton);
>
> horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding,
> QSizePolicy::Minimum);
>
> horizontalLayout->addItem(horizontalSpacer);
>
> pushButton_2 = new QPushButton("LONG", this);
> pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
>
> horizontalLayout->addWidget(pushButton_2);
>
>
> This code was generated by QtDesigner and the Designer preview shows it
> correctly ie both buttons take the minimal space required to display
> the text properly and the spacer occopies the rest.
>
> However in my code both buttons have the same size. If I add more text to
> the LONG button then that grows .
>
> I'm so confused, been trying to get this to work, on and off, for three
> days...
>
> br Kusti
>
You say that the Designer preview shows the buttons correctly but your
code does not. Does this mean that you are not using the Designer
generated .ui files in your application? Are you trying to do everything
in code? It has been a while since I went through this so I don't
remember the details, but I have had problems trying to duplicate
Designer generated code in my own code, so I use the .ui files generated
by Designer in my applications.
More information about the Qt-interest-old
mailing list