(C++) QGraphicsProxyWidget
February 24, 2017 · View on GitHub
(C++)
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.
- QGraphicsProxyWidget example 1: screenshot (png), displays a single QLineEdit
- QGraphicsProxyWidget example 2: screenshot (png), displays multiple QLineEdits
- QGraphicsProxyWidget example 3: screenshot (png), multiple movable widgets with a window frame
- QGraphicsProxyWidget example 4: screenshot (png), multiple unmovable widgets despite QGraphicsItem::ItemIsMovable flag
- QGraphicsProxyWidget example 5: screenshot (png), multiple movable widgets that cannot be focused on
- QGraphicsProxyWidget example 6: screenshot (png), multiple movable focusable widgets
Technical facts
Operating system(s) or programming environment(s)
Lubuntu 12.10 (quantal)
Qt Creator 2.5.2
- G++ 4.7.2
Libraries used:
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(); }