删除QGridLayout中的所有间距 [英] Remove all spacing in QGridLayout

查看:310
本文介绍了删除QGridLayout中的所有间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以编程方式(使用Qt 4.6)构建一个包含一系列QPushButton的窗口,这些窗口都打包在一起.它应该看起来像这样(我称之为工具箱):

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):

工具箱图片http://img99.imageshack.us/img99/9853/examplezk.png

因此,我创建了一个Qbox派生的Toolbox类,该类具有以下构造函数:

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:

结果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.

推荐答案

显然,这被认为是正常的事情:请参见相应的错误报告,该报告已关闭.报告的解决方法似乎不适用于我.

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.

这篇关于删除QGridLayout中的所有间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆