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)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: CppQGraphicsProxyWidgetExample2.pro

 

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

 

 

 

 

 

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);
  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();
}

 

 

 

 

 

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