(C++) QGraphicsProxyWidget

February 24, 2017 · View on GitHub

 

 

 

 

 

(C++) Qt QGraphicsProxyWidget

 

QGraphicsProxyWidget is the class that is returned when a QWidget is added to a QGraphicsScene. From that moment on, the QWidget can be modified in its original form, but also by its QGraphicsProxyWidget, the latter enabling for scaling and rotation.

 

 

 

 

 

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

  • Qt Qt: version 4.8.3 (32 bit)
  • STL STL: GNU ISO C++ Library, version 4.7.2

 

 

 

 

 

Qt project file: CppQGraphicsProxyWidgetExample1.pro

 


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

 

 

 

 

 

main.cpp

 


#include <QApplication> #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(100,100,400,200);   view.show();   //Create a QWidget   QLineEdit *const edit = new QLineEdit;   //Add the QWidget and obtain its proxy   QGraphicsProxyWidget * const proxy = scene.addWidget(edit);   //Modify the widget by using its proxy   proxy->setScale(2.0);   proxy->setRotation(30);   return app.exec(); }