When you see a scroll bar it is from an internal QScrollArea, where your legend items is inside. In your situation the scroll area seems to be too small to show the labels - changing the attributes of the labels won't help as they have their correct size.
I didn't mean to change the attribute of the label itself, I meant to query the each label to find out what size it wanted to be, then calling setFixedWidth() on each legend with based on the maximum label size.
After putting some debug statements into your code: is the width of the legend below its sizeHint ?
The size hint width is -1 for some reason? Here's how I'm creating the legends:
legends.append(legend);
legend->setMinimumHeight(0);
legend->setMaxColumns(1);
connect(plot,
SIGNAL(legendDataChanged
(QVariant,QList<QwtLegendData>
)),
legend,
SLOT(updateLegend
(QVariant,QList<QwtLegendData>
)));
grid->addWidget(legend, i, 1);
QwtLegend* legend = new QwtLegend();
legends.append(legend);
legend->setMinimumHeight(0);
legend->setMaxColumns(1);
connect(plot, SIGNAL(legendDataChanged(QVariant,QList<QwtLegendData>)),
legend, SLOT(updateLegend(QVariant,QList<QwtLegendData>)));
grid->addWidget(legend, i, 1);
To copy to clipboard, switch view to plain text mode
And then in my mainWidget::resizeEvent() I've got:
{
qDebug("legend width %d, size hint width %d", legend->width(), legend->sizeHint().width());
}
foreach (QwtLegend* legend, legends)
{
qDebug("legend width %d, size hint width %d", legend->width(), legend->sizeHint().width());
}
To copy to clipboard, switch view to plain text mode
Which produces:
legend width 437, size hint width -1
If yes what happens when assign a different horizontal QSizePolicy ( should be QSizePolicy::MinimumExpanding )?
But I don't think I want MinimumExpanding for the legends, do I? I've got MinimumExpanding for the QwtPlots in column 0, if I set MinimumExpanding on the QwtLegends the QGridLayout gives 50% width to each column, which isn't what I want. Although I guess could play around with QGridLayout::setColumnStretch(). It seems like I want MinimumExpanding on the plots and Maximum or Preferred on the legends, so the legends get just enough horizontal space to not have a scrollbar, but the plots get the majority of the screen real estate. But putting Maximum on makes it a little too small and then the scrollbars show up.
Bookmarks