Graphic legend minimum size fix

This commit is contained in:
2021-02-25 18:09:27 +03:00
parent 8a36ff0b61
commit 6b4a903764

View File

@@ -30,6 +30,7 @@ __GraphicRegistrator__ __graphic_registrator__;
class LegendScrollArea: public QScrollArea {
public:
LegendScrollArea(QWidget * w): QScrollArea() {
minimum_hei = 0;
setFrameShape(QFrame::NoFrame);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
setWidgetResizable(true);
@@ -40,6 +41,7 @@ public:
viewport()->setAutoFillBackground(false);
w->setAutoFillBackground(false);
}
int minimum_hei;
protected:
virtual QSize sizeHint() const {
QSize ret;
@@ -47,6 +49,9 @@ protected:
ret = widget()->sizeHint();
return ret;
}
virtual QSize minimumSizeHint() const {
return QSize(1, minimum_hei);
}
};
@@ -1597,15 +1602,29 @@ void Graphic::updateLegend(bool es) {
int row = 0, col = 0;
bool lv = ui->scrollLegend->isVisibleTo(this);
ui->scrollLegend->hide();
LegendScrollArea * leg_sa = (LegendScrollArea *)ui->scrollLegend->layout()->itemAt(0)->widget();
for (int i = 0; i < graphics.size(); i++) {
ui->layoutLegend->addWidget(graphics[i].pb,row,col);
graphics[i].pb->show();
QCheckBox * check = graphics[i].pb;
check->show();
if (leg_sa->minimum_hei == 0) {
leg_sa->minimum_hei = ui->widgetLegend->sizeHint().height();
/*#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
QTimer::singleShot(0, this, [this,leg_sa,check](){
leg_sa->minimum_hei = check->sizeHint().height();
leg_sa->updateGeometry();
qDebug() << leg_sa->minimum_hei << ui->widgetLegend->sizeHint();
});
#else
leg_sa->minimum_hei = check->sizeHint().height();
#endif*/
}
col++;
if (col > maxcol) {col = 0; row++;}
}
ui->gridLayout->invalidate();
ui->scrollLegend->setVisible(lv);
ui->scrollLegend->layout()->itemAt(0)->widget()->updateGeometry();
leg_sa->updateGeometry();
//ui->gridLayout->invalidate();
leg_update = true;
if (es) emit graphicSettingsChanged();