简体   繁体   中英

Qt window resize event after resize is done

I have a QtChart in a QDialog and I use a simple QWidget to show it on the screen. I need to resize this hart whenever the dialog window is resized by user.

This is how I add the chart to the dialog (in constructor):

// Setup chart view to show the chart
mChartView = new QChartView(mChart, ui->widget);
mChartView->setParent(this);
mChartView->resize(ui->widget->size());
mChartView->setRenderHint(QPainter::Antialiasing);

I have overrided the resizeEvent of the QDialog in my own dialog:

void CurveDialog::resizeEvent(QResizeEvent *event)
{
    mChartView->resize(ui->widget->size());
}

This works, and the chart gets resized...but the problem is it is terribly slow! because it will resize for all the steps that user drags the window corner to resize it!

How can I do the resize only when there resize is done? I wanted to use a timer but this looks like a dirty hack! any better ideas?

Qt provides a layout system to manage the geometries of child widgets within a widget. A layout will arrange the size and the position of each child to ensure that it will take all the available space.

The layout will automatically resize the child widgets when the parent is resized:

QChartView *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);

QDialog* dialog = new QDialog();
QVBoxLayout* layoutDialog = new QVBoxLayout(dialog);

QWidget* widget = new QWidget();
QVBoxLayout* layoutWidget = new QVBoxLayout(widget);

layoutDialog->addWidget(widget);
layoutWidget->addWidget(chartView);

dialog->exec();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM