#include <QtGui>
#include "flowlayout.h"
#include <QResizeEvent>
public:
/*QHBoxLayout *l = new QHBoxLayout(this);
l->addWidget(new QPushButton(QString("Button %1").arg(i)));
QComboBox *cb = new QComboBox;
cb->addItems(QStringList() << QString::number(i));
cb->setMinimumWidth(50);
l->addWidget(cb);*/
Host
->setObjectName
(QString::fromUtf8("Host"));
Host
->setGeometry
(QRect(20,
50,
61,
41));
Info
->setObjectName
(QString::fromUtf8("Info"));
Info
->setGeometry
(QRect(80,
60,
31,
21));
qlGameNum
= new QLabel( this );
qlGameNum
->setObjectName
(QString::fromUtf8("qlGameNum"));
qlGameNum
->setGeometry
(QRect(10,
0,
46,
14));
qlGameTitle
= new QLabel(this);
qlGameTitle
->setObjectName
(QString::fromUtf8("qlGameTitle"));
qlGameTitle
->setGeometry
(QRect(10,
20,
61,
16));
qlPlayerNum
= new QLabel(this);
qlPlayerNum
->setObjectName
(QString::fromUtf8("qlPlayerNum"));
qlPlayerNum
->setGeometry
(QRect(130,
0,
21,
16));
qlIcons
->setObjectName
(QString::fromUtf8("qlIcons"));
qlIcons
->setGeometry
(QRect(65,
0,
61,
20));
setFixedSize( 200, 100 );
}
};
public:
if(e
->type
()!=QEvent::Resize) return false;
int w = ev->size().width()-20; // cheating here
setFixedSize(w, layout()->heightForWidth(w));
return false;
}
};
int main(int argc, char **argv){
FlowLayout *l = new FlowLayout(wgt);
for(int i=0;i<20;i++)
l->addWidget(new Complex(i+1, wgt));
wgt->setMinimumSize( wgt->sizeHint() );
area.setWidget(wgt);
area.installEventFilter(wgt);
area.show();
return app.exec();
}
#include <QtGui>
#include "flowlayout.h"
#include <QResizeEvent>
class Complex : public QWidget {
public:
QPushButton *Host;
QPushButton *Info;
QLabel *qlGameNum;
QLabel *qlGameTitle;
QLabel *qlPlayerNum;
QLabel *qlIcons;
Complex(int i, QWidget *parent=0): QWidget(parent){
/*QHBoxLayout *l = new QHBoxLayout(this);
l->addWidget(new QPushButton(QString("Button %1").arg(i)));
QComboBox *cb = new QComboBox;
cb->addItems(QStringList() << QString::number(i));
cb->setMinimumWidth(50);
l->addWidget(cb);*/
Host = new QPushButton( this ) ;
Host->setObjectName(QString::fromUtf8("Host"));
Host->setGeometry(QRect(20, 50, 61, 41));
Info = new QPushButton( this );
Info->setObjectName(QString::fromUtf8("Info"));
Info->setGeometry(QRect(80, 60, 31, 21));
qlGameNum = new QLabel( this );
qlGameNum->setObjectName(QString::fromUtf8("qlGameNum"));
qlGameNum->setGeometry(QRect(10, 0, 46, 14));
qlGameTitle = new QLabel(this);
qlGameTitle->setObjectName(QString::fromUtf8("qlGameTitle"));
qlGameTitle->setGeometry(QRect(10, 20, 61, 16));
qlPlayerNum = new QLabel(this);
qlPlayerNum->setObjectName(QString::fromUtf8("qlPlayerNum"));
qlPlayerNum->setGeometry(QRect(130, 0, 21, 16));
qlIcons = new QLabel(this);
qlIcons->setObjectName(QString::fromUtf8("qlIcons"));
qlIcons->setGeometry(QRect(65, 0, 61, 20));
Host->setText(QApplication::translate("Form", "Host", 0, QApplication::UnicodeUTF8));
Info->setText(QApplication::translate("Form", "Info", 0, QApplication::UnicodeUTF8));
qlGameNum->setText(QApplication::translate("Form", "Game 1", 0, QApplication::UnicodeUTF8));
qlGameTitle->setText(QApplication::translate("Form", "Game Title", 0, QApplication::UnicodeUTF8));
qlPlayerNum->setText(QApplication::translate("Form", "0/8", 0, QApplication::UnicodeUTF8));
setFixedSize( 200, 100 );
}
};
class Widget : public QWidget {
public:
Widget(QWidget *parent = 0) : QWidget(parent){}
bool eventFilter(QObject *o, QEvent *e){
if(e->type()!=QEvent::Resize) return false;
QResizeEvent *ev = (QResizeEvent*)e;
int w = ev->size().width()-20; // cheating here
setFixedSize(w, layout()->heightForWidth(w));
return false;
}
};
int main(int argc, char **argv){
QApplication app(argc, argv);
QScrollArea area;
QWidget *wgt = new Widget;
FlowLayout *l = new FlowLayout(wgt);
for(int i=0;i<20;i++)
l->addWidget(new Complex(i+1, wgt));
wgt->setMinimumSize( wgt->sizeHint() );
area.setWidget(wgt);
area.installEventFilter(wgt);
area.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks