How to use QGraphicsProxyWidget in Qt
Article Metadata
Tested with
Devices(s): S60 Emulator
Compatibility
Platform(s): Qt
Platform Security
Signing Required: Self-Signed
Capabilities: None
Article
Keywords: QGraphicsProxyWidget,QGraphicsScene,QGraphicsView,QLineEdit,QLabel
Created: mind_freak
(10 Apr 2009)
Last edited: hamishwillee
(11 Oct 2012)
Contents |
Introduction
The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene. QGraphicsProxyWidget embeds QWidget-based widgets, for example, a QPushButton, QFontComboBox, or even QFileDialog, into QGraphicsScene. It forwards events between the two objects and translates between QWidget's integer-based geometry and QGraphicsWidget's qreal-based geometry.
QGraphicsProxyWidget takes care of automatically embedding popup children of embedded widgets through creating a child proxy for each popup.
Souce Code
Main.cpp
#include "proxywidget.h"
#include <QtGui>
#include <QApplication>
#include<QGroupBox>
#include<QFormLayout>
#include<QLabel>
#include<QLineEdit>
#include<QGraphicsScene>
#include<QGraphicsProxyWidget>
#include<QGraphicsView>
#include<QPushButton>
#include<QComboBox>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGroupBox *groupBox = new QGroupBox("Contact Details",this);
QLabel *numberLabel = new QLabel("Telephone number",this);
QLineEdit *numberEdit = new QLineEdit(this);
QPushButton *but=new QPushButton("Helloooo",this);
QFormLayout *layout = new QFormLayout;
QComboBox *box=new QComboBox(this);
box->addItem("Nokia");
box->addItem("Qt");
box->addItem("Widget");
box->addItem("N96");
box->addItem("London");
box->addItem("Finland");
box->addItem("NewYork");
box->addItem("Symbian");
box->addItem("Paris");
box->addItem("Budapest");
layout->addRow(numberLabel, numberEdit);
layout->addRow(but);
layout->addRow(box);
groupBox->setLayout(layout);
QGraphicsScene scene;
QGraphicsProxyWidget *proxy = scene.addWidget(groupBox);
QGraphicsView view(&scene);
view.show();
return a.exec();
}
ScreenShot
Before Clicking The ComboBox
Note the changes in the scrollBar of the widget
More about QGraphicProxyWidget


