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.
  • J Offline
    J Offline
    jaskmar
    wrote on 21 Feb 2013, 17:59 last edited by
    #1

    Hello,
    I want to use widget that I could draw on and use it with Qt Designer/Qt Creator together. Do I have to write it on my own and implement paintEvent or is there any easier way? Maybe there is widget with "repainted()" signal implemented or something.

    I don't want to create widget dinamically because it could make problem with layout.

    PS: Sorry for my english.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Santosh Reddy
      wrote on 21 Feb 2013, 19:01 last edited by
      #2

      bq. I want to use widget that I could draw on and use it with Qt Designer/Qt Creator together.

      How you plan to draw? Do you mean interactive drawing using mouse?

      SS

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jaskmar
        wrote on 21 Feb 2013, 19:36 last edited by
        #3

        No. In my case I want to display an Image from QImage object. Maybe write some text from QString in addition. That's all.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Santosh Reddy
          wrote on 21 Feb 2013, 19:56 last edited by
          #4

          Then you need write a Qt Designer plug-in

          Oh well, wait…
          If it is simple QImage and some QString, you could use QStackedWidget in Qt Designed it self

          SS

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Santosh Reddy
            wrote on 21 Feb 2013, 19:57 last edited by
            #5

            <merged with earlier post>

            SS

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jaskmar
              wrote on 21 Feb 2013, 20:15 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 21 Feb 2013, 20:18 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 21 Feb 2013, 20:22 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 21 Feb 2013, 20:30 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 21 Feb 2013, 21:03 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
                      • C Online
                        C Online
                        Chris Kawa
                        Lifetime Qt Champion
                        wrote on 21 Feb 2013, 21:18 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 21 Feb 2013, 21:23 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 21 Feb 2013, 21:57 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 22 Feb 2013, 08:44 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 22 Feb 2013, 09:58 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 22 Feb 2013, 10:34 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 22 Feb 2013, 11:12 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

                                    8/17

                                    21 Feb 2013, 20:22

                                    • Login

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