Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all spacing in QGridLayout

Tags:

macos

qt

I'm trying to build programmaticaly (with Qt 4.6) a window containing a series of QPushButton's, all packed together. It should look like so (which I call a toolbox):

toolbox image http://img99.imageshack.us/img99/9853/examplezk.png

So, I created a Toolbox class, deriving from QWidget, that has the following constructor:

Toolbox::Toolbox (void)
  : QWidget (0, Qt::Tool)
{
  setWindowTitle (tr ("Toolbox"));

  QGridLayout *group = new QGridLayout (this);
  group->setSpacing (0);
  group->setContentsMargins (0, 0, 0, 0);
  group->setSizeConstraint (QLayout::SetFixedSize);
  setLayout (group);

  unsigned k = 0;
  QPushButton *buttons = new QPushButton[6];
  for (unsigned i = 0; i < 3; i++)
    for (unsigned j = 0; j < 2; j++)
    {
      buttons[k].setIcon (QIcon ("test.png"));
      buttons[k].setIconSize (QSize (32, 32));
      buttons[k].setContentsMargins (0, 0, 0, 0);
      buttons[k].setCheckable (true);
      buttons[k].setAutoExclusive (true);

      group->addWidget (&buttons[k], i, j);
      k++;
    }
  buttons[1].setChecked (true);

Somehow, it does not work and my buttons don't end up packed together:

result http://img9.imageshack.us/img9/774/resultr.png

I can't manage to remove this vertical spacing (and the margins surrounding the entire array). Any help is welcome.

like image 991
F'x Avatar asked Feb 04 '10 22:02

F'x


1 Answers

Apparently, this is considered a normal thing: see the corresponding bug report, which was closed. The workaround reported there doesn't seem to work for me.

like image 51
F'x Avatar answered Oct 05 '22 23:10

F'x