Results 1 to 2 of 2

Thread: Create toolbox of QGraphicsSvgItem

  1. #1
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Create toolbox of QGraphicsSvgItem

    An example simple of code in order to create a toolbox of GraphicsSvgItem present in the QGraphicsScene ?

  2. #2
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Create toolbox of QGraphicsSvgItem

    File lista.h:

    #include <QListWidget>
    #include <QtGui/QGroupBox>

    class Lista : public QListWidget
    {
    public:
    Lista(QGroupBox *grp);

    protected:
    void mousePressEvent(QMouseEvent *event);
    };
    --------------------------------------------------------
    File lista.cpp:

    #include "lista.h"

    #include <QDebug>

    Lista::Lista(QGroupBox *grp) : QListWidget(grp)
    {
    }

    void Lista::mousePressEvent(QMouseEvent *event)
    {
    qDebug() << "Lista::mousePressEvent().";

    QListWidget::mousePressEvent(event);
    }
    --------------------------------------------------------
    File risorsa.qrc:

    <RCC>
    <qresource>
    <file>robot.svg</file>
    <file>ostacolo.svg</file>
    </qresource>
    </RCC>
    --------------------------------------------------------
    File mainwindow.h:

    #include <QMainWindow>
    #include <QtGui/QGroupBox>
    #include <QtGui/QListWidget>

    #include "lista.h"

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    protected:

    private:
    Ui::MainWindow *ui;
    QGroupBox *gruppo;
    Lista *lista;
    };
    --------------------------------------------------------
    File mainwindow.cpp:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    this->resize(520, 520);
    gruppo = new QGroupBox(centralWidget());
    gruppo->setTitle("Elementi");
    gruppo->setGeometry(QRect(20, 30, 140, 470));
    lista = new Lista(gruppo);
    lista->setGeometry(QRect(10, 20, 120, 440));
    lista->setSortingEnabled(true);
    QListWidgetItem *item1 = new QListWidgetItem(QIcon(":/ostacolo.svg"), "Ostacolo", lista);
    QListWidgetItem *item2 = new QListWidgetItem(QIcon(":/robot.svg"), "Robot", lista);
    lista->insertItem(1, item1);//Item insertion
    lista->insertItem(2, item2);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }
    --------------------------------------------------------

Similar Threads

  1. Problem when using QGraphicsSvgItem
    By NoRulez in forum Qt Programming
    Replies: 0
    Last Post: 20th February 2010, 17:49
  2. problem with toolbox
    By wagmare in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2008, 09:52
  3. Problem with QGraphicsSvgItem
    By drake1983 in forum Newbie
    Replies: 1
    Last Post: 8th July 2007, 07:05
  4. put a toolbox
    By mickey in forum Newbie
    Replies: 4
    Last Post: 27th August 2006, 15:35
  5. toolbox
    By mickey in forum Newbie
    Replies: 7
    Last Post: 14th April 2006, 12:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.