#include <QtGui>
class Panel : public QGraphicsWidget
{
Q_OBJECT
public:
QGraphicsWidget(parent, wFlags) {
setGeometry(rect);
}
Q_UNUSED(widget);
painter
->setRenderHints
(QPainter::Antialiasing);
pen.setWidth(1);
painter->setPen(pen);
painter->setBrush(Qt::BDiagPattern);
painter->drawEllipse(rect);
}
private:
};
{
Q_OBJECT
public:
resize(800, 600);
QGraphicsWidget* container = new QGraphicsWidget;
m_lo = new QGraphicsLinearLayout;
m_lo->setOrientation(Qt::Horizontal);
m_lo->setSpacing(30);
container->setLayout(m_lo);
scene->addItem(container);
for (int i = 0; i < 10; i++) {
QGraphicsLinearLayout* row = new QGraphicsLinearLayout;
row->setOrientation(Qt::Vertical);
row->setSpacing(30);
m_lo->addItem(row);
for (int j = 0; j < 10; j++) {
Panel* p = new Panel;
row->addItem(p);
}
}
setCentralWidget(view);
}
private:
QGraphicsLinearLayout* m_lo;
};
int main(int argc, char** argv)
{
MainWindow mw;
mw.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
class Panel : public QGraphicsWidget
{
Q_OBJECT
public:
Panel(QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = 0) :
QGraphicsWidget(parent, wFlags) {
rect = QRectF(0, 0, 40, 40);
setGeometry(rect);
}
void paint(QPainter* painter,
const QStyleOptionGraphicsItem*, QWidget* widget = 0) {
Q_UNUSED(widget);
painter->setRenderHints(QPainter::Antialiasing);
QPen pen(Qt::black);
pen.setWidth(1);
painter->setPen(pen);
painter->setBrush(Qt::BDiagPattern);
painter->drawEllipse(rect);
}
private:
QRectF rect;
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget* parent=0) : QMainWindow(parent) {
resize(800, 600);
QGraphicsScene* scene = new QGraphicsScene;
QGraphicsWidget* container = new QGraphicsWidget;
m_lo = new QGraphicsLinearLayout;
m_lo->setOrientation(Qt::Horizontal);
m_lo->setSpacing(30);
container->setLayout(m_lo);
scene->addItem(container);
for (int i = 0; i < 10; i++) {
QGraphicsLinearLayout* row = new QGraphicsLinearLayout;
row->setOrientation(Qt::Vertical);
row->setSpacing(30);
m_lo->addItem(row);
for (int j = 0; j < 10; j++) {
Panel* p = new Panel;
row->addItem(p);
}
}
QGraphicsView* view = new QGraphicsView(scene);
setCentralWidget(view);
}
private:
QGraphicsLinearLayout* m_lo;
};
int main(int argc, char** argv)
{
QApplication app(argc, argv);
MainWindow mw;
mw.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks