[Qt-interest] problem with QGraphicsView

Sajauddin Shariff Mohammad shariff at mic.co.in
Thu Jun 25 12:07:31 CEST 2009


Dear Friends,
Iam new to graphics programming in QT. I want to show the image selected by the user in graphics view widget. Ican show the image but a small problem with it.
 My .h and .CPP files are as follows
.H file
class myWidget : public QWidget, Ui_Form
{
   Q_OBJECT
   public:
   QPixmap *pix;
   QGraphicsScene *scene;
   QString imgFilename;
   QGraphicsItem *prvItm, *currItm;
   myWidget(QWidget *parent = 0);
   ~myWidget();
   public slots:
   void on_browseButton_clicked();
   void on_showButton_clicked();
};
.cpp file
myWidget::myWidget(QWidget *parent):QWidget(parent)
{
   pix = new QPixmap();
   scene = new QGraphicsScene();
   currItm = NULL;
   setupUi(this);
   graphicsView->setScene(scene);
   graphicsView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
   graphicsView->setAlignment(Qt::AlignCenter);
}
myWidget::~myWidget()
{
}
void myWidget::on_browseButton_clicked()
{
   QString filename;
   filename = QFileDialog::getOpenFileName(this, tr("Select Image File"), "/data", tr("Images (*.bmp *.png *.jpg)"));
   browseLE->setText(filename);
}
void myWidget::on_showButton_clicked()
{
   QPixmap myPix;
   imgFilename = browseLE->text();
   myPix.fill();
   myPix.load(imgFilename);
   if(currItm!=NULL)  scene->removeItem(currItm);
   currItm = scene->addPixmap(myPix);
}
The image that is being displayed in graphics view is not alligned at the center. 
Pleas eguide me what should I do so that the image is shown at thecenter of the graphics view.
Regards,
Sajauddin Shariff
shariff at mic.co.in
+91-998-904-5546
Confidentiality NoticeThe information contained in this Electronic Message 
and any ATTACHMENTs to this message are intended for the EXCLUSIVE USE of 
the ADDRESSEE(s) and may contain CONFIDENTIAL or PRIVILEGED information. 
If you are not the intended recipient, please notify the SENDER at MIC or
itsupport at mic.co.in immediately and DESTROY all copies of this message 
and any attachments.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090625/83bc7fcf/attachment.html 


More information about the Qt-interest-old mailing list