两个工具按钮和 hboxlayout 之间的空间
Posted
技术标签:
【中文标题】两个工具按钮和 hboxlayout 之间的空间【英文标题】:space between two tool buttons and hboxlayout 【发布时间】:2016-12-21 11:03:23 【问题描述】:如果窗口显示或隐藏,我正在尝试删除两个工具按钮并添加其他小部件并使用偶数过滤器添加 hboxlayout。 问题是当我删除水平的垫片时,两个按钮成功绑定在一起,但是当我添加一个小部件时,工具按钮和小部件之间有一个空格,如图所示。我将如何删除该空间?
这里是初始化
setWindowTitle(tr("Points of Interest"));
m_splitter->setContentsMargins(0, 0, 0, 3);
m_gridLayout = new QGridLayout(this);
m_gridLayout->addWidget(m_splitter, 0, 0, 1, 1);
m_hBoxLayout = new QHBoxLayout(this);
m_gridLayout->addLayout(m_hBoxLayout, 1, 0, 1, 1);
m_hBoxLayout->addWidget(m_myPoiButton);
m_hBoxLayout->addStretch();
m_hBoxLayout->addWidget(m_myPoiFilterButton);
m_gridLayout->setVerticalSpacing(0);
这是代码和图片:
if (event->type() == QEvent::Show)
if (obj == m_poiItemWidget)
bool visibleName = false, visibleHeight = false, visibleRange = false;
visibleName = m_namePoiFilter.isVisible();
visibleHeight = m_widgetHeight.isVisible();
visibleRange = m_widgetRange.isVisible();
m_namePoiFilter.setVisible(visibleName);
m_widgetHeight.setVisible(visibleHeight);
m_widgetRange.setVisible(visibleRange);
m_hBoxLayout->addWidget(m_myPoiButton);
for (int i = 0; i < m_hBoxLayout->count(); ++i)
QSpacerItem *spacer = m_hBoxLayout->itemAt(i)->spacerItem();
if (spacer)
delete m_hBoxLayout->takeAt(i);
break;
m_hBoxLayout->addWidget(m_myPoiFilterButton);
m_hBoxLayout->addStretch();
m_hBoxLayout->addWidget(&m_namePoiFilter);
m_hBoxLayout->addWidget(&m_widgetHeight);
m_hBoxLayout->addWidget(&m_widgetRange);
if (event->type() == QEvent::Hide)
if (obj == m_poiItemWidget)
bool visibleName = false, visibleHeight = false, visibleRange = false;
visibleName = m_namePoiFilter.isVisible();
visibleHeight = m_widgetHeight.isVisible();
visibleRange = m_widgetRange.isVisible();
m_namePoiFilter.setVisible(visibleName);
m_widgetHeight.setVisible(visibleHeight);
m_widgetRange.setVisible(visibleRange);
for (int i = 0; i < m_hBoxLayout->count(); ++i)
QSpacerItem *spacer = m_hBoxLayout->itemAt(i)->spacerItem();
if (spacer)
delete m_hBoxLayout->takeAt(i);
break;
m_hBoxLayout->addWidget(m_myPoiButton);
m_hBoxLayout->addStretch();
m_hBoxLayout->addWidget(m_myPoiFilterButton);
m_hBoxLayout->addWidget(&m_namePoiFilter);
m_hBoxLayout->addWidget(&m_widgetHeight);
m_hBoxLayout->addWidget(&m_widgetRange);
【问题讨论】:
【参考方案1】:在初始化中试试这个
m_gridLayout->setContentsMargins(0,0,0,0);
m_hBoxLayout->setContentsMargins(0,0,0,0);
【讨论】:
不幸的是,这并没有解决问题。 QToolbutton之间还有一个空格以上是关于两个工具按钮和 hboxlayout 之间的空间的主要内容,如果未能解决你的问题,请参考以下文章
减少BlackBerry中Horizo ntal Field Manager中2个按钮之间的空间