Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QGraphicsPixmapItem && QGraphicsGridLayout
Forum Updated to NodeBB v4.3 + New Features

[Solved] QGraphicsPixmapItem && QGraphicsGridLayout

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 8.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    luca
    wrote on last edited by
    #1

    Hi all,

    is there a way to put some QGraphicsPixmapItem in a grid?

    In QT 4.6 documentation there is a QGraphicsGridLayout example:

    @
    QGraphicsScene scene;
    QGraphicsWidget *textEdit = scene.addWidget(new QTextEdit);
    QGraphicsWidget *pushButton = scene.addWidget(new QPushButton);

    QGraphicsGridLayout *layout = new QGraphicsGridLayout;
    layout->addItem(textEdit, 0, 0);
    layout->addItem(pushButton, 0, 1);

    QGraphicsWidget *form = new QGraphicsWidget;
    form->setLayout(layout);
    scene.addItem(form);
    @

    but it use a QGraphicsWidget and I need to use a QGraphicsPixmapItem to show some pixmap in a grid.

    1 Reply Last reply
    0
    • I Offline
      I Offline
      iunknwn
      wrote on last edited by
      #2

      try this: layout->addItem(graphicsPixmapItem->parentWidget(), 0, 2); //if you are using QT 4.4+

      Vista x64 with Qt 4.8.2 and VS2010

      1 Reply Last reply
      0
      • I Offline
        I Offline
        iunknwn
        wrote on last edited by
        #3

        Well said it too early without trying. I don't think there is a direct way to use QGraphicsGridLayout for QGraphicsPixmapItem. It is for QGraphicWidgets only.

        May be you can determine view/scene size calculate positions on the fly and position them accordingly in the scene.

        Vista x64 with Qt 4.8.2 and VS2010

        1 Reply Last reply
        0
        • L Offline
          L Offline
          luca
          wrote on last edited by
          #4

          Thanks,

          Now I'm trying the example I posted before:

          @
          QGraphicsScene scene;
          QGraphicsWidget *textEdit = scene.addWidget(new QTextEdit);
          QGraphicsWidget *pushButton = scene.addWidget(new QPushButton);

          QGraphicsGridLayout *layout = new QGraphicsGridLayout;
          layout->addItem(textEdit, 0, 0);
          layout->addItem(pushButton, 0, 1);

          QGraphicsWidget *form = new QGraphicsWidget;
          form->setLayout(layout);
          scene.addItem(form);
          @

          but I get a compiling error:

          @
          error: cannot convert 'QGraphicsProxyWidget*' to 'QGraphicsWidget*' in assignment
          @

          and it refer to the line:

          @
          QGraphicsWidget *textEdit = scene.addWidget(new QTextEdit);
          @

          What is the problem?

          1 Reply Last reply
          0
          • I Offline
            I Offline
            iunknwn
            wrote on last edited by
            #5

            add

            @#include <QtGui>@

            or

            specifically you are missing:

            @#include <QtGui/QGraphicsProxyWidget>@

            Below find full working example
            @
            #include <QtGui/QApplication>
            #include <QtGui/QGraphicsProxyWidget>
            #include <QtGui/QGraphicsScene>
            #include <QtGui/QTextEdit>
            #include <QtGui/QPushButton>
            #include <QtGui/QGraphicsGridLayout>
            #include <QtGui/QGraphicsView>

            int main(int argc, char **argv)
            {
            QApplication app(argc, argv);

            QGraphicsScene scene;
            QGraphicsWidget *textEdit = scene.addWidget(new QTextEdit);
            QGraphicsWidget *pushButton = scene.addWidget(new QPushButton);

            QGraphicsGridLayout *layout = new QGraphicsGridLayout;
            layout->addItem(textEdit, 0, 0);
            layout->addItem(pushButton, 0, 1);

            QGraphicsWidget *form = new QGraphicsWidget;
            form->setLayout(layout);
            scene.addItem(form);

            QGraphicsView view(&scene);
            view.show();

            return app.exec();
            }

            @

            Vista x64 with Qt 4.8.2 and VS2010

            1 Reply Last reply
            0
            • L Offline
              L Offline
              luca
              wrote on last edited by
              #6

              Ok, thanks and sorry for the stupid question, it solved... :-)

              Now I'm trying to put my pixmap in a QLabel and the use the same way of the example.

              I'll tell you if it works...

              1 Reply Last reply
              0
              • I Offline
                I Offline
                iunknwn
                wrote on last edited by
                #7

                QLabel with QPixmaps laied out with QGraphicsGridLayout would do the trick and would definitely work. Threre is not need to do QGraphicsPixmapItem.

                Vista x64 with Qt 4.8.2 and VS2010

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  luca
                  wrote on last edited by
                  #8

                  The new solution works!

                  @
                  QGraphicsGridLayout *ggl = new QGraphicsGridLayout;
                  QPixmap pixmap1;
                  QPixmap pixmap2;
                  ...
                  QLabel *pixmap_widget = new QLabel;
                  pixmap_widget->setPixmap(pixmap1);
                  QGraphicsProxyWidget *pixmap_graphics_widget1 = graphicsScene->addWidget(pixmap_widget);
                  pixmap_widget = new QLabel;
                  pixmap_widget->setPixmap(pixmap2);
                  QGraphicsProxyWidget *pixmap_graphics_widget2 = graphicsScene->addWidget(pixmap_widget);
                  ggl->addItem(pixmap_graphics_widget1,0,0);
                  ggl->addItem(pixmap_graphics_widget2,0,1);
                  QGraphicsWidget *form = new QGraphicsWidget;
                  form->setLayout(ggl);
                  graphicsScene->addItem(form);
                  @

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    luca
                    wrote on last edited by
                    #9

                    Thanks for your help!

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved