I have a button that spans two columns in a Grid Layou开发者_StackOverflowt. The button is about half the width of its cell and I want it to be centered.
gridLayout->addWidget(btn3, 2, 6, 1, 2);
aligns the button the left of the cell, which I would assume to be the default. I tried
gridLayout->addWidget(btn3, 2, 6, 1, 2, Qt::AlignHCenter);
and the button disappears. Where did my button go and why is it not in the center of my layout cell?
I am using QT opensoure in Linux (ubuntu 10.04).
A bit of context:
gridLayout->addWidget(btn1, 2, 3);
gridLayout->addWidget(btn2, 2, 5);
gridLayout->addWidget(btn3, 2, 6, 1, 2);
gridLayout->addWidget(btn4, 2, 8);
gridLayout->addWidget(btn5, 2, 10);
I want btn3 to be in the center of its two-column-spanning cell, but when I attempt to pass Qt:AlignCenter as the 6th argument in the addWidget() method, btn3 disappears.
You are using a ColumnSpan of 2, your button is probably under some other Widget of your gridLayout. Try changing your code to:
gridLayout->addWidget(btn3, 2, 6, 1, 1, Qt::AlignCenter);
It works fine to me.
精彩评论