×
Namespaces

Variants
Actions

Transformation of QGraphicsView

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Creator IDE V 4.5 and Emulator
Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition, Qt 4.5
Symbian
Article
Keywords: QGraphicsScene,QGraphicsView
Created: mind_freak (10 Jun 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

Overview

QGraphicsView supports the same affine transformations as QPainter does through QGraphicsView::setMatrix(). By applying a transformation to the view, you can easily add support for common navigation features such as zooming and rotating.

Classes used:

  • QGraphicsScene - Provides a surface for managing a large number of 2D graphical items
  • QGraphicsView - Provides a widget for displaying the contents of a QGraphicsScene.

Preconditions

  • Download and Install the Qt SDK

Source Code

Header File

#ifndef TRANS_H
#define TRANS_H
 
#include <QtGui/QDialog>
#include "ui_trans.h"
#include<QGraphicsScene>
#include<QGraphicsView>
#include<QPushButton>
#include<QWidget>
#include<QHBoxLayout>
#include<QTextEdit>
#include<QVBoxLayout>
#include<QString>
 
class trans : public QDialog
{
Q_OBJECT
 
public:
trans(QWidget *parent = 0);
~trans();
 
private:
QGraphicsScene *scene;
QGraphicsView *view;
QVBoxLayout *lay;
QPushButton *but1;
QPushButton *but2;
QPushButton *but3;
QPushButton *but4;
QWidget *win;
QTextEdit *txt;
QVBoxLayout *vlay;
 
 
private slots:
void zoomIn(){view->scale(1.2, 1.2);}
void zoomOut(){ view->scale(1/1.2,1/1.2);}
void xhg();
void rotateLeft() { view->rotate(-90); }
void rotateRight() { view->rotate(90); }
 
};
#endif // TRANS_H

Cpp File

#include "trans.h"
#include "ui_trans.h"
 
trans::trans(QWidget *parent)
: QWidget(parent)
{
list=new QListWidget(this);
list->resize(0,0);
list1=new QListWidget(this);
lay=new QHBoxLayout(this);
list->addItem("Nokia");
list->addItem("Samsung");
list->addItem("Motorola");
list1->addItem("Nokia 6630");
list1->addItem("5800 Xpress Music");
list1->addItem("N96");
 
list->setSelectionMode(QAbstractItemView::SingleSelection);
list->setDragEnabled(true);
list->setDragDropMode(QAbstractItemView::InternalMove);
list->viewport()->setAcceptDrops(true);
 
list->setDropIndicatorShown(true);
 
list1->setSelectionMode(QAbstractItemView::SingleSelection);
list1->setDragEnabled(true);
list1->viewport()->setAcceptDrops(true);
 
list1->setDropIndicatorShown(true);
 
lay->addWidget(list);
lay->addWidget(list1);
setLayout(lay);
list->setStyleSheet("* { background-color:rgb(150,147,88);color:rgb(255,255,255); padding: 7px}}");
list1->setStyleSheet("* { background-color:rgb(150,140,70);color:rgb(255,255,255); padding: 7px}}");
resize(200,200);
showMaximized();
}
 
trans::~trans()
{
// No need to delete any object it has got a parent which is properly deleted.
}
void trans::xhg()
{
QString s3= txt->toPlainText();
 
scene->addText(s3);
scene->update();
view->show();
 
}

Screen shot

Traans001.jpg

This page was last modified on 11 October 2012, at 04:18.
57 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×