{
public:
protected:
signals:
void sizeChange
(QSize size
);
};
class QCustomResizeWidget
: QFrame{
public:
QCustomResizeWidget
(QWidget *parent
) public slots:
void sizeChangeSlot
(QSize size
);
protected:
QSize sizeHint
(void) const;
QSize minimumSizeHint
(void) const;
};
class QCustomMainPage : QWidget
{
public:
QCustomMainPage(QWidget *parent)
protected:
void resizeEvent ( QResizeEvent *re );
signals:
void sizeChange(QSize size);
};
class QCustomResizeWidget : QFrame
{
public:
QCustomResizeWidget (QWidget *parent)
public slots:
void sizeChangeSlot(QSize size);
protected:
QSize sizeHint(void) const;
QSize minimumSizeHint(void) const;
QSize currentsize;
};
To copy to clipboard, switch view to plain text mode
QCustomResizeWidget
::QCustomResizeWidget(QWidget *parent
):QFrame (parent
){ clayout->addWidget(label1);
clayout->addWidget(label2);
}
void QCustomResizeWidgetsize
::ChangeSlot(QSize size
){ currentsize
= QSize(size.
width()/10, size.
width()/10);
// keep it square this->setFixedSize(currentsize);
}
QSize QCustomResizeWidgetsize
::sizeHint(void) const{ return this->currentsize;
}
QSize minimumSizeHint
(void) const{ // return this->currentsize;
return QSize(1,
1);
// allow widget to resize down to 1,1 (to get this partially working) }
QCustomResizeWidget *customwidget1 = new QCustomResizeWidget;
connect(this,
SIGNAL(sizeChange
(QSize)), customwidget1,
SLOT(ChangeSlot
(QSize)));
QCustomResizeWidget *customwidget2 = new QCustomResizeWidget;
connect(this,
SIGNAL(sizeChange
(QSize)), customwidget1,
SLOT(ChangeSlot
(QSize)));
QCustomResizeWidget *customwidget3 = new QCustomResizeWidget;
connect(this,
SIGNAL(sizeChange
(QSize)), customwidget1,
SLOT(ChangeSlot
(QSize)));
QCustomResizeWidget *customwidget4 = new QCustomResizeWidget;
connect(this,
SIGNAL(sizeChange
(QSize)), customwidget1,
SLOT(ChangeSlot
(QSize)));
grid->addWidget(customwidget1, 0,0);
grid->addWidget(customwidget1, 0,1);
grid->addWidget(customwidget1, 1,0);
grid->addWidget(customwidget1, 1,1);
}
emit sizeChange(re->size());
}
QCustomResizeWidget::QCustomResizeWidget(QWidget *parent):QFrame (parent){
QLabel *label1 = new QLabel("label1");
QLabel *label2 = new QLabel("label2");
QVBoxLayout *clayout = new QVBoxLayout(this);
clayout->addWidget(label1);
clayout->addWidget(label2);
}
void QCustomResizeWidgetsize::ChangeSlot(QSize size){
currentsize = QSize(size.width()/10, size.width()/10); // keep it square
this->setFixedSize(currentsize);
}
QSize QCustomResizeWidgetsize::sizeHint(void) const{
return this->currentsize;
}
QSize minimumSizeHint(void) const{
// return this->currentsize;
return QSize(1,1); // allow widget to resize down to 1,1 (to get this partially working)
}
QCustomMainPage::QCustomMainPage(QWidget *parent) : QWidget(parent){
QCustomResizeWidget *customwidget1 = new QCustomResizeWidget;
connect(this, SIGNAL(sizeChange(QSize)), customwidget1, SLOT(ChangeSlot(QSize)));
QCustomResizeWidget *customwidget2 = new QCustomResizeWidget;
connect(this, SIGNAL(sizeChange(QSize)), customwidget1, SLOT(ChangeSlot(QSize)));
QCustomResizeWidget *customwidget3 = new QCustomResizeWidget;
connect(this, SIGNAL(sizeChange(QSize)), customwidget1, SLOT(ChangeSlot(QSize)));
QCustomResizeWidget *customwidget4 = new QCustomResizeWidget;
connect(this, SIGNAL(sizeChange(QSize)), customwidget1, SLOT(ChangeSlot(QSize)));
QGridLayout *grid = new QGridLayout(this);
grid->addWidget(customwidget1, 0,0);
grid->addWidget(customwidget1, 0,1);
grid->addWidget(customwidget1, 1,0);
grid->addWidget(customwidget1, 1,1);
}
QCustomMainPage::resizeEvent(QResizeEvent *re ){
emit sizeChange(re->size());
}
To copy to clipboard, switch view to plain text mode
Bookmarks