#include <cmath>
#include <QApplication>
#include <QDesktopWidget>
#include <QGraphicsProxyWidget>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QLineEdit>
int main(int argc, char **argv)
{
//Create the application
QApplication app(argc, argv);
//Create the Qt Graphics Framework components
QGraphicsScene scene;
QGraphicsView view(&scene);
view.setGeometry(0,0,600,400);
{
//Put the dialog in the screen center
const QRect screen = QApplication::desktop()->screenGeometry();
view.move( screen.center() - view.rect().center() );
}
view.show();
//Create the QLineEdit instances
const int sz = 10;
std::vector<QGraphicsProxyWidget *> proxies;
for (int i=0; i!=sz; ++i)
{
QLineEdit *const edit = new QLineEdit;
edit->setGeometry(0,0,64,22);
edit->setText(QString("#") + QString::number(i));
//Add the QWidget and obtain its proxy
QGraphicsProxyWidget * const proxy = scene.addWidget(edit);
proxies.push_back(proxy);
}
const double ray = 100.0; //pixels
for (int i=0; i!=sz; ++i)
{
const double angle = 2.0 * M_PI * static_cast<double>(i) / static_cast<double>(sz);
const int x = static_cast<int>(0.0 + (std::sin(angle) * ray));
const int y = static_cast<int>(0.0 - (std::cos(angle) * ray));
QGraphicsProxyWidget * const proxy = proxies[i];
proxy->setRotation(angle * 360.0 / (2.0 * M_PI));
proxy->setPos(x,y);
}
return app.exec();
}
|