PDA

View Full Version : space between two tool buttons and hboxlayout



andreahmed
21st December 2016, 15:09
I'm trying to remove two tool buttons and add the other widgets and add an hboxlayout using an even filter if the window is shown or hidden. The problem is when I remove the spacer the horizontal one, the two buttons are tied together successfully, but when I add a widget, there is a space between the tool button and the widget as shown in the figure. how would I remove that space ?

here is the initialization

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


12254


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

}

}

anda_skoa
22nd December 2016, 12:45
Hard to tell without any screenshot or the ability to execute this, but have you checked if the space is caused by layout spacing?

Cheers,
_