'Fit minimal size of a QDockPanel after QLabel content update

I have a QDockWidget with a QGroupBox as the top widget, with QVBoxLayout applied. This contains a QChartView and a QLabel.

The QLabel contains a text composed of several lines of different length.

First, I would like to have the QChartView the same width and height as the QLabel.

Second, as the content of the QLabel is updated by setText(...) in a Slot method, its content changes in height and width. So I would like to update the width and height of the QChartView above it.

For the moment, I only achieved to grow the entire DockPanel to accomodate longer and wider QLabel content, but not to shrink back when this content is narrower and less wide...

I did play with a lot of things, without real success (here a snippet of the Slot method that updates the QLabel content...):

        self.fkChartView.hide()
        self.pPDetailsLabel.hide()
        self.pPDetailsLabel.parent().hide()
        self.pPDetailsLabel.setText(self.canvas.grayScottModel.getPearsonPatternDescription(specie=type))
        self.pPDetailsLabel.updateGeometry()
        self.pPDetailsLabel.parent().updateGeometry()
        self.pPDetailsLabel.parent().update()

        self.pPDetailsDock.updateGeometry()
        self.pPDetailsDock.update()

        self.pPDetailsLabel.show()
        self.pPDetailsLabel.parent().show()

        # print(self.pPDetailsLabel.sizeHint())
        self.fkChartView.setMinimumHeight(self.pPDetailsLabel.size().width())
        self.fkChartView.setMaximumHeight(self.pPDetailsLabel.size().width())
        self.fkChartView.setMinimumWidth(self.pPDetailsLabel.size().width())
        self.fkChartView.setMaximumWidth(self.pPDetailsLabel.size().width())
        self.fkChartView.updateGeometry()
        self.fkChartView.show()
        self.fkChartView.updateGeometry()
        self.fkChartView.update()

I tried to hide the widgets, so they forget their sizes and/or sizeHint (not sure). I tried a few updateGeometry() and update() too, but it does not seem to help.

An idea, anyone?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source