qt多个窗口排列

网友投稿 711 2022-11-30

qt多个窗口排列

qt多个窗口排列

#ifndef QSPLITTERWIDGET_H#define QSPLITTERWIDGET_H#include #include #include class QSplitterWidget : public QWidget{ Q_OBJECTpublic: explicit QSplitterWidget(QWidget *parent = 0);protected: void arrangeWidget();signals:public: void addWidget(QWidget* w,int index); void addWidgetFirst(QWidget* w); void addWidgetEnd(QWidget* w); void reduceWidgetFirst(); void reduceWidgetEnd(); void reduceWidget(QString objectName);private: QList listw; int space;};#endif // QSPLITTERWIDGET_H

#include "qsplitterwidget.h"#include "formwidget.h"#include QSplitterWidget::QSplitterWidget(QWidget *parent) : QWidget(parent){ space = 5;}void QSplitterWidget::arrangeWidget(){ int fixedSizeW = 0; int fixedSizeH = 0; int hPoint = 0; int wPoint = 0; int recordHnum = 0; int recordWnum = 0; for(int i = 1; i <= 30; i++){ if(listw.size () == 1 ){ listw.at (0)->setGeometry (space,space,this->width () - space*2,this->height () - space*2); listw.at (0)->show (); break; }else if(listw.size () > i*i && listw.size () <= (i+1)*(i+1)){ fixedSizeW = (this->width () - space*(i+2)) / (i+1); fixedSizeH = (this->height () - space*(i+2)) / (i+1); hPoint = space; for(int j = 0; j < listw.size (); j++){ hPoint = (fixedSizeH + space)*recordHnum + space; wPoint = (fixedSizeW + space)*recordWnum + space; listw.at (j)->setGeometry (wPoint,hPoint,fixedSizeW,fixedSizeH); listw.at (j)->show (); recordWnum++; if(recordWnum >= i+1){ recordWnum = 0; recordHnum++; } } break; } }}void QSplitterWidget::addWidget(QWidget *w, int index){ w->setParent (this); listw.insert (index,w); arrangeWidget();}void QSplitterWidget::addWidgetFirst(QWidget *w){ w->setParent (this); listw.insert (0,w); arrangeWidget();}void QSplitterWidget::addWidgetEnd(QWidget *w){ w->setParent (this); listw.append (w); arrangeWidget();}void QSplitterWidget::reduceWidgetFirst(){ if(listw.size () >= 1){ QWidget *w = listw.at (0); listw.removeAt (0); w->close (); arrangeWidget(); }}void QSplitterWidget::reduceWidgetEnd(){ if(listw.size () >= 1){ QWidget *w = listw.at (listw.size ()-1); listw.removeAt (listw.size ()-1); w->close (); arrangeWidget(); }}void QSplitterWidget::reduceWidget(QString objectName){ for(int i = 0; i < listw.size (); i++){ if(listw.at (i)->objectName () == objectName){ QWidget *w = listw.at (i); listw.removeAt (i); w->close (); arrangeWidget(); } }}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:opencv 将Mat类型从CV_32F转CV_8U
下一篇:QTableWidget左上角添加按钮
相关文章

 发表评论

暂时没有评论,来抢沙发吧~