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] Widget I can draw on.
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Widget I can draw on.

Scheduled Pinned Locked Moved General and Desktop
17 Posts 4 Posters 6.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.
  • S Offline
    S Offline
    Santosh Reddy
    wrote on last edited by
    #5

    <merged with earlier post>

    SS

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jaskmar
      wrote on last edited by
      #6

      Could I? How? QImage does not inherits from QWidget...

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Santosh Reddy
        wrote on last edited by
        #7

        You can set the background image using stylesheets

        SS

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jaskmar
          wrote on last edited by
          #8

          And if I want to create an animation by showing QImage's one-by-one?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sam
            wrote on last edited by
            #9

            For animations you can have a look at "QPropertyAnimation Class":http://qt-project.org/doc/qt-5.0/qtcore/qpropertyanimation.html

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jaskmar
              wrote on last edited by
              #10

              :/
              I can not imagine how should it work. I can't even display simple image loaded from file. So which property would I animate. On which widget?

              Ohh, I am afraid I will have to write my own widget indeed. But that's strange for me as I have noticed that Qt liblary is well-equipped compared to wxWidgets, where wxStaticBitmap exists.

              PS: Sorry for my English again. Is it hard to understand what I write? :D

              1 Reply Last reply
              0
              • Chris KawaC Offline
                Chris KawaC Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by
                #11

                For static images you can use simple QLabel and QLabel::setPixmap. For animation there's a QLabel::setMovie. You could play around with a custom QIODevice for the QMovie.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Sam
                  wrote on last edited by
                  #12

                  There is an example available in Qt creator "Basic Drawing Example":http://doc.qt.digia.com/stable/painting-basicdrawing.html and also for basic reference you can have a look at this "tutorial":http://www.voidrealms.com/viewtutorial.aspx?id=35. In order to set a background image you can use "Qt StyleSheets":http://qt-project.org/doc/qt-4.8/stylesheet-examples.html

                  There are many tutorials available at "wwww.voidrealms.com":http://www.voidrealms.com/tutorials.aspx?filter=qt based on Qt 4 which are helpful for a start.

                  Regards
                  Soumitra

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jaskmar
                    wrote on last edited by
                    #13

                    I have already seen the example. It is based on writing own widget, but I am asking about different way (I have written the reason earlier). Maybe Krzysztof's way is satisfactory, I will try.

                    In the midtime I found a solution using QGraphicsView, which unfortunately doesn't work. My code:
                    @
                    QImage Image("/path/to/image.png");
                    QPixmap Pixmap;
                    Pixmap.convertFromImage(Image);
                    QGraphicsPixmapItem Item(Pixmap);
                    QGraphicsScene *Scene = ui->GraphicsView->scene();
                    Scene->addItem(&Item);
                    @
                    The code compiles, but I receive an error during execution. In english it would be "Unexpected program termination" or sth. like that.


                    EDIT:
                    Ok, Krzysztof's way is what I was looking for. About QMovie, I briefly checked this class documentation and I didn't notice the way to make an animation using several QImage's or QPixmap's. I will be thinking about it deeper tommorow. Is it better way than simple replacing images in a thread? Maybe simpler?

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Santosh Reddy
                      wrote on last edited by
                      #14

                      QGraphicsPixmapItem is created on stack, are you sure that it will remain in scope for all the time during scene is in scope. Instead you could create it on heap (using new)

                      SS

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        jaskmar
                        wrote on last edited by
                        #15

                        No, the problem is different. I have already tried this way:
                        @
                        QImage *Image = new QImage("/path/a.png");
                        QPixmap *Pixmap = new QPixmap;
                        Pixmap->convertFromImage(*Image);
                        QGraphicsPixmapItem *Item = new QGraphicsPixmapItem(*Pixmap);
                        QGraphicsScene *Scene = ui->GraphicsView->scene();
                        Scene->addItem(Item);
                        @
                        And the result is the same.
                        The error-generating line is the last one.

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          Santosh Reddy
                          wrote on last edited by
                          #16

                          Then I have say that the view does not have scene set, what deos ui->GraphicsView->scene(); return?

                          SS

                          1 Reply Last reply
                          0
                          • J Offline
                            J Offline
                            jaskmar
                            wrote on last edited by
                            #17

                            Of course.
                            So there are two ways:

                            using QGraphicsView:
                            @
                            QImage *Image = new QImage("/home/foo/a.png");
                            QPixmap *Pixmap = new QPixmap;
                            Pixmap->convertFromImage(*Image);
                            QGraphicsPixmapItem *Item = new QGraphicsPixmapItem(*Pixmap);
                            QGraphicsScene *Scene = new QGraphicsScene;
                            ui->GraphicsView->setScene(Scene);
                            Scene->addItem(Item);
                            @

                            or using QLabel
                            @
                            QImage Image("/home/foo/a.png");
                            QPixmap Pixmap;
                            Pixmap.convertFromImage(Image);
                            ui->label->setPixmap(Pixmap);
                            @

                            And this thread is SOLVED.
                            Thanks a lot and deep Greathings.

                            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