Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.






(C++) Qt QGraphicsProxyWidget example 2


QGraphicsProxyWidget example 2 is a QGraphicsProxyWidget example.







Technical facts


Application type(s)

Operating system(s) or programming environment(s)


Project type:

C++ standard:


Libraries used:






Qt project file: CppQGraphicsProxyWidgetExample2.pro


QT       += core
QT       += gui
QMAKE_CXXFLAGS += -Wextra -Werror
TARGET = CppQGraphicsProxyWidgetExample2
CONFIG   += console
CONFIG   -= app_bundle
SOURCES += main.cpp








#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);
    //Put the dialog in the screen center
    const QRect screen = QApplication::desktop()->screenGeometry();
    view.move( screen.center() - view.rect().center() );

  //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->setText(QString("#") + QString::number(i));
    //Add the QWidget and obtain its proxy
    QGraphicsProxyWidget * const proxy = scene.addWidget(edit);

  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));
  return app.exec();






Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.


Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml