How to make all objects shrinkable in QStatusBar
Unsolved
General and Desktop
-
As this GIF.
In my implementation, I use addPermanentWidget() to add some QLabel, but only can make the last QLable shrinkable when window size change.
-
class ResizableWidget : public QWidget { public: ResizableWidget(QWidget *parent = nullptr) : QWidget(parent), resizing(false) {} protected: void mousePressEvent(QMouseEvent *event) override { if (event->button() == Qt::LeftButton) { resizing = true; lastPos = event->globalPos(); } } void mouseMoveEvent(QMouseEvent *event) override { if (resizing) { int deltaX = event->globalX() - lastPos.x(); int deltaY = event->globalY() - lastPos.y(); resize(width() + deltaX, height() + deltaY); lastPos = event->globalPos(); } } void mouseReleaseEvent(QMouseEvent *event) override { Q_UNUSED(event); resizing = false; } void paintEvent(QPaintEvent *event) override { Q_UNUSED(event); QPainter painter(this); painter.fillRect(rect(), Qt::blue); } private: bool resizing; QPoint lastPos; };