Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QGraphicsItem>
- #include <QPixmap>
- #include <QPointF>
- #include <QSizeF>
- class Escena;
- class Item: public QGraphicsItem{
- private:
- QString nombre;
- QPixmap imagen;
- bool seleccion;
- QPointF punto;
- QSizeF tamanio;
- public:
- Item(QPixmap imagen, QGraphicsItem *padre = nullptr);
- void setNombre(QString);
- QString getNombre();
- void setImagen(QPixmap);
- QPixmap getImagen();
- void setPunto(QPointF punto);
- QPointF getPunto();
- void setTamanio(QSizeF tamanio);
- QSizeF getTamanio();
- void setSeleccion(bool seleccion);
- bool getSeleccion();
- protected:
- QRectF boundingRect() const override;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem
- *option,QWidget *widget) override;
- };
- #include "item.h"
- #include "escena.h"
- #include <QDebug>
- #include <QPainter>
- #include <QPointF>
- Item::Item(QPixmap imagen, QGraphicsItem *padre):QGraphicsItem (padre)
- {
- this->imagen = imagen;
- }
- void Item::setNombre(QString nombre){
- this->nombre = nombre;
- }
- QString Item::getNombre(){
- return nombre;
- }
- void Item::setImagen(QPixmap imagen){
- this->imagen = imagen;
- }
- QPixmap Item::getImagen(){
- return imagen;
- }
- void Item::setPunto(QPointF punto){
- this->punto = punto;
- }
- QPointF Item::getPunto(){
- return punto;
- }
- void Item::setTamanio(QSizeF tamanio){
- this->tamanio = tamanio;
- }
- QSizeF Item::getTamanio(){
- return tamanio;
- }
- void Item::setSeleccion(bool seleccion){
- this->seleccion = seleccion;
- }
- bool Item::getSeleccion(){
- return seleccion;
- }
- QRectF Item::boundingRect() const{
- return QRectF(punto.x(), punto.y(), tamanio.width(),
- tamanio.height());
- }
- void Item::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
- QWidget *){
- painter->drawPixmap(punto.x(), punto.y(), tamanio.width(),
- tamanio.height(),imagen);
- }
- #include <QGraphicsScene>
- #include <QGraphicsItem>
- #include "item.h"
- class Item;
- class Escena : public QGraphicsScene{
- public:
- Escena(QObject *padre = nullptr);
- };
- #include "escena.h"
- #include <QPixmap>
- #include <QGraphicsItem>
- #define XPOS 0.0//constantes para las dimensiones de la escena
- #define YPOS 0.0
- #define WIDTH 663.0
- #define HEIGHT 410.0
- Escena::Escena(QObject *padre):QGraphicsScene(XPOS, YPOS, WIDTH,
- HEIGHT, padre){
- Item *c = new Item(QPixmap(":/img/targetOff.png"));
- c->setPunto(QPointF(0.0,0.0));
- c->setTamanio(QSizeF(64.0,64.0));
- c->setNombre("A");
- c->setSeleccion(false);
- c->setFlag(QGraphicsItem::ItemIsMovable,true);//Movilidad
- addItem(c);
- Item *c2 = new Item(QPixmap(":/img/targetOff.png"));
- c2->setPunto(QPointF(300.0,200.0));
- c2->setTamanio(QSizeF(64.0,64.0));
- c2->setNombre("Item B");
- c2->setSeleccion(false);
- c2->setAcceptHoverEvents(true);
- c2->setFlag(QGraphicsItem::ItemIsMovable,true);//movilidad
- addItem(c2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement