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. Graphics classes troubles...
Qt 6.11 is out! See what's new in the release blog

Graphics classes troubles...

Scheduled Pinned Locked Moved General and Desktop
14 Posts 4 Posters 7.8k 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.
  • P Offline
    P Offline
    Peppy
    wrote on last edited by
    #3

    Thanks, and my first problem? What do you think?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #4

      [quote author="Peppy" date="1304202756"]Thanks, and my first problem? What do you think?[/quote]

      Honestly I did not understand what exactly is the problem. Btw what are you trying to achieve?

      If you want just to set a background color it would be easier to use:

      @setStyleSheet("background-color:rgb(255,127,0);");@

      QGraphicsView inherits QAbstractScrollArea, which inherits QFrame, which inherits QWidget so you should be able to call setStyleSheet :)

      Cheers,
      Leon

      http://anavi.org/

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Peppy
        wrote on last edited by
        #5

        I have this code:
        @
        QGraphicScene scene;
        scene.addRect(QRect(0,0,1000,700));

        GraphicsView gv(&scene);
        gv.show();
        @
        And GraphicView class:
        @
        class GraphicsView : public QGraphicsView
        {
        public:
        explicit GraphicsView(QGraphicsScene* scene) : QGraphicsView(scene) { }

        protected:
        void paintEvent(QPaintEvent*);
        };
        void GraphicsView::paintEvent(QPaintEvent*)
        {
        QPainter painter(this);
        painter.setBrush(QBrush(QColor(255,127,0)));
        painter.drawRect(this->sceneRect());
        }
        @
        Problem is, that debugger writes messages as I wrote above, and it doesn't draw anything....

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leon.anavi
          wrote on last edited by
          #6

          Please check "this thread at stackoverflow":http://stackoverflow.com/questions/1117847/qt-4-5-how-do-i-get-a-qpainter-device-in-a-qgraphicsview the proposed solution is to use "viewport()":http://doc.qt.nokia.com/latest/qabstractscrollarea.html#viewport instead of this:

          @QPainter painter(viewport());@

          Best regards,
          Leon

          http://anavi.org/

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Peppy
            wrote on last edited by
            #7

            Great! It works! Oh my God, it should be in docs...

            1 Reply Last reply
            0
            • L Offline
              L Offline
              leon.anavi
              wrote on last edited by
              #8

              Cool :) So now both issues are solved thanks to the viewport!

              http://anavi.org/

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Peppy
                wrote on last edited by
                #9

                Yes, but this important thing should be in docs, I think. :)

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  leon.anavi
                  wrote on last edited by
                  #10

                  [quote author="Peppy" date="1304204584"]Yes, but this important thing should be in docs, I think. :)[/quote]

                  You can add a wiki howto article about this issue here at Qt Developer network :)

                  http://anavi.org/

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    deimos
                    wrote on last edited by
                    #11

                    You can also reimplement "QGraphicsScene::drawBackground":http://doc.qt.nokia.com/latest/qgraphicsscene.html#drawBackground

                    or take a look also at "backgroundBrush":http://doc.qt.nokia.com/latest/qgraphicsscene.html#backgroundBrush-prop

                    regards

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      Peppy
                      wrote on last edited by
                      #12

                      When I used backgroundBrush (image via QBrush class) image was repeating on all axis. :)...

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        deimos
                        wrote on last edited by
                        #13

                        yes :)
                        you can reimplement drawbackground like this:

                        @void GraphicsView::drawBackground(QPainter *painter,
                        const QRectF &f)
                        {
                        Q_UNUSED(f);
                        QRectF rect;
                        rect=this->mapToScene(0,0, this->width(), this->height()).boundingRect();
                        painter->fillRect( rect, QColor(255,127,0));
                        }@

                        1 Reply Last reply
                        0
                        • Z Offline
                          Z Offline
                          ZapB
                          wrote on last edited by
                          #14

                          [quote author="Peppy" date="1304204584"]Yes, but this important thing should be in docs, I think. :)[/quote]

                          QGV inherits QAbstractScrollArea and the docs there tell you all about the distinction between the viewport and the scroll area. Always a good idea to read the docs for the class(es) that the class of interest publically inherits too.

                          Nokia Certified Qt Specialist
                          Interested in hearing about Qt related work

                          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