QPainter's setWorldTransform default behavior?Undefined, unspecified and implementation-defined behaviorUndefined behavior and sequence pointsWhere to put default parameter value in C++?Can code that is valid in both C and C++ produce different behavior when compiled in each language?QDockWidget tabify/splitDockWidget weird behavior / bug?QSerialPort inconsistent behavior depending on starting baud rateQTextBrowser behavior different between debug and release buildHow to modify QtWebEngine behavior when link is clicked?How to disable the default copy behavior in QTreeView?Change only a specific Default Parameter on a function

Escape a backup date in a file name

Is HostGator storing my password in plaintext?

Purchasing a ticket for someone else in another country?

How to Reset Passwords on Multiple Websites Easily?

Customer Requests (Sometimes) Drive Me Bonkers!

Is there a good way to store credentials outside of a password manager?

Implement the Thanos sorting algorithm

Would a high gravity rocky planet be guaranteed to have an atmosphere?

Do sorcerers' Subtle Spells require a skill check to be unseen?

Why Were Madagascar and New Zealand Discovered So Late?

What is the opposite of 'gravitas'?

Arithmetic mean geometric mean inequality unclear

Increase performance creating Mandelbrot set in python

How can I kill an app using Terminal?

Why, precisely, is argon used in neutrino experiments?

Can the discrete variable be a negative number?

How does the UK government determine the size of a mandate?

Opposite of a diet

I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?

How to safely derail a train during transit?

Why escape if the_content isnt?

How long to clear the 'suck zone' of a turbofan after start is initiated?

Avoiding estate tax by giving multiple gifts

How to run a prison with the smallest amount of guards?



QPainter's setWorldTransform default behavior?


Undefined, unspecified and implementation-defined behaviorUndefined behavior and sequence pointsWhere to put default parameter value in C++?Can code that is valid in both C and C++ produce different behavior when compiled in each language?QDockWidget tabify/splitDockWidget weird behavior / bug?QSerialPort inconsistent behavior depending on starting baud rateQTextBrowser behavior different between debug and release buildHow to modify QtWebEngine behavior when link is clicked?How to disable the default copy behavior in QTreeView?Change only a specific Default Parameter on a function













0















The following code shows the window on the left (see image below). Nevertheless, uncommenting the line marked with /*[identity transform]*/, the window in the right is generated. As reported by qInfo() in the console output, nothing relevant for the coordinate transform seems to change.



Could anybody explain me the reason? I can't find it in the documentation.



class SomeItem : public QGraphicsEllipseItem

public:
explicit SomeItem(const QRectF& rect, QGraphicsItem* parent = nullptr) :
QGraphicsEllipseItem(rect,parent)

void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)

QTransform tr;
//painter->setWorldTransform(tr); /*[identity transform]*/
qInfo() << painter->window().left() << painter->window().right()
<< painter->window().top() << painter->window().bottom();
qInfo() << painter->viewport().left() << painter->viewport().right()
<< painter->viewport().top() << painter->viewport().bottom();
qInfo() << painter->matrix().m11() << painter->matrix().m12()
<< painter->matrix().m21() << painter->matrix().m22();
/* <--->*/
QGraphicsEllipseItem::paint(painter,option,widget);

;

int main(int argc, char **argv)

QApplication app (argc, argv);

QGraphicsScene ms;
ms.setSceneRect(-20,-20,40,40);
SomeItem* si = new SomeItem(QRectF(-10,-10,20,20));
ms.addItem(si);
QGraphicsView view(&ms);
view.show();

return app.exec();



Console output (for both cases):



0 197 0 97
0 197 0 97
1 0 0 1


Result with commented line (left) and with uncommented line (right)










share|improve this question




























    0















    The following code shows the window on the left (see image below). Nevertheless, uncommenting the line marked with /*[identity transform]*/, the window in the right is generated. As reported by qInfo() in the console output, nothing relevant for the coordinate transform seems to change.



    Could anybody explain me the reason? I can't find it in the documentation.



    class SomeItem : public QGraphicsEllipseItem

    public:
    explicit SomeItem(const QRectF& rect, QGraphicsItem* parent = nullptr) :
    QGraphicsEllipseItem(rect,parent)

    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
    QWidget *widget)

    QTransform tr;
    //painter->setWorldTransform(tr); /*[identity transform]*/
    qInfo() << painter->window().left() << painter->window().right()
    << painter->window().top() << painter->window().bottom();
    qInfo() << painter->viewport().left() << painter->viewport().right()
    << painter->viewport().top() << painter->viewport().bottom();
    qInfo() << painter->matrix().m11() << painter->matrix().m12()
    << painter->matrix().m21() << painter->matrix().m22();
    /* <--->*/
    QGraphicsEllipseItem::paint(painter,option,widget);

    ;

    int main(int argc, char **argv)

    QApplication app (argc, argv);

    QGraphicsScene ms;
    ms.setSceneRect(-20,-20,40,40);
    SomeItem* si = new SomeItem(QRectF(-10,-10,20,20));
    ms.addItem(si);
    QGraphicsView view(&ms);
    view.show();

    return app.exec();



    Console output (for both cases):



    0 197 0 97
    0 197 0 97
    1 0 0 1


    Result with commented line (left) and with uncommented line (right)










    share|improve this question


























      0












      0








      0








      The following code shows the window on the left (see image below). Nevertheless, uncommenting the line marked with /*[identity transform]*/, the window in the right is generated. As reported by qInfo() in the console output, nothing relevant for the coordinate transform seems to change.



      Could anybody explain me the reason? I can't find it in the documentation.



      class SomeItem : public QGraphicsEllipseItem

      public:
      explicit SomeItem(const QRectF& rect, QGraphicsItem* parent = nullptr) :
      QGraphicsEllipseItem(rect,parent)

      void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
      QWidget *widget)

      QTransform tr;
      //painter->setWorldTransform(tr); /*[identity transform]*/
      qInfo() << painter->window().left() << painter->window().right()
      << painter->window().top() << painter->window().bottom();
      qInfo() << painter->viewport().left() << painter->viewport().right()
      << painter->viewport().top() << painter->viewport().bottom();
      qInfo() << painter->matrix().m11() << painter->matrix().m12()
      << painter->matrix().m21() << painter->matrix().m22();
      /* <--->*/
      QGraphicsEllipseItem::paint(painter,option,widget);

      ;

      int main(int argc, char **argv)

      QApplication app (argc, argv);

      QGraphicsScene ms;
      ms.setSceneRect(-20,-20,40,40);
      SomeItem* si = new SomeItem(QRectF(-10,-10,20,20));
      ms.addItem(si);
      QGraphicsView view(&ms);
      view.show();

      return app.exec();



      Console output (for both cases):



      0 197 0 97
      0 197 0 97
      1 0 0 1


      Result with commented line (left) and with uncommented line (right)










      share|improve this question
















      The following code shows the window on the left (see image below). Nevertheless, uncommenting the line marked with /*[identity transform]*/, the window in the right is generated. As reported by qInfo() in the console output, nothing relevant for the coordinate transform seems to change.



      Could anybody explain me the reason? I can't find it in the documentation.



      class SomeItem : public QGraphicsEllipseItem

      public:
      explicit SomeItem(const QRectF& rect, QGraphicsItem* parent = nullptr) :
      QGraphicsEllipseItem(rect,parent)

      void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
      QWidget *widget)

      QTransform tr;
      //painter->setWorldTransform(tr); /*[identity transform]*/
      qInfo() << painter->window().left() << painter->window().right()
      << painter->window().top() << painter->window().bottom();
      qInfo() << painter->viewport().left() << painter->viewport().right()
      << painter->viewport().top() << painter->viewport().bottom();
      qInfo() << painter->matrix().m11() << painter->matrix().m12()
      << painter->matrix().m21() << painter->matrix().m22();
      /* <--->*/
      QGraphicsEllipseItem::paint(painter,option,widget);

      ;

      int main(int argc, char **argv)

      QApplication app (argc, argv);

      QGraphicsScene ms;
      ms.setSceneRect(-20,-20,40,40);
      SomeItem* si = new SomeItem(QRectF(-10,-10,20,20));
      ms.addItem(si);
      QGraphicsView view(&ms);
      view.show();

      return app.exec();



      Console output (for both cases):



      0 197 0 97
      0 197 0 97
      1 0 0 1


      Result with commented line (left) and with uncommented line (right)







      c++ qt qt5






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 21 at 17:09







      JtTest

















      asked Mar 21 at 15:11









      JtTestJtTest

      177




      177






















          2 Answers
          2






          active

          oldest

          votes


















          1














          Paint method uses local coordinate system. This means that origin of painter is usually located at top left corner of QGraphicsItem (note this is base class for everything in QGraphicsScene). In case of QGraphicsEllipseItem it must be center of it.



          Apparently this is implemented by transforming QPainter used by QGraphicsView widget when void QWidget::paintEvent(QPaintEvent *event) is processed.



          Simply each QGraphicsItem in QGraphicsScene painted by QGraphicsView transform painter for its needs.



          When you restore identity transformation, you got a painter in state which applies for QGraphicsView paint event. So it is top left corner of it.



          You where lucky that nothing got broken since you are painting outside of boundingRect.






          share|improve this answer

























          • Thanks for the thorough explanation. I still don't get why I am painting outside of boundingRect; as far as I understand, if QPainter acts in local coordinate and tr is an identity transform, nothing is moved out of the boundingRect...could you explain me, please?

            – JtTest
            Mar 21 at 18:07


















          0














          Reasoning on Marek's answer, I guess to have found a geometrical explaination. My fault was to inspect painter->matrix() rather than painter->transform(). Indeed, Qmatrix does not manage translation, while painter->transform().m31() and painter->transform().m32() do.



          Substituting the following lines



          qInfo() << painter->transform().m31() << painter->transform().m32();


          in place of /*<--->*/ provides console outputs for the two cases, respectively,



          99 49


          and



          0 0





          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55283613%2fqpainters-setworldtransform-default-behavior%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Paint method uses local coordinate system. This means that origin of painter is usually located at top left corner of QGraphicsItem (note this is base class for everything in QGraphicsScene). In case of QGraphicsEllipseItem it must be center of it.



            Apparently this is implemented by transforming QPainter used by QGraphicsView widget when void QWidget::paintEvent(QPaintEvent *event) is processed.



            Simply each QGraphicsItem in QGraphicsScene painted by QGraphicsView transform painter for its needs.



            When you restore identity transformation, you got a painter in state which applies for QGraphicsView paint event. So it is top left corner of it.



            You where lucky that nothing got broken since you are painting outside of boundingRect.






            share|improve this answer

























            • Thanks for the thorough explanation. I still don't get why I am painting outside of boundingRect; as far as I understand, if QPainter acts in local coordinate and tr is an identity transform, nothing is moved out of the boundingRect...could you explain me, please?

              – JtTest
              Mar 21 at 18:07















            1














            Paint method uses local coordinate system. This means that origin of painter is usually located at top left corner of QGraphicsItem (note this is base class for everything in QGraphicsScene). In case of QGraphicsEllipseItem it must be center of it.



            Apparently this is implemented by transforming QPainter used by QGraphicsView widget when void QWidget::paintEvent(QPaintEvent *event) is processed.



            Simply each QGraphicsItem in QGraphicsScene painted by QGraphicsView transform painter for its needs.



            When you restore identity transformation, you got a painter in state which applies for QGraphicsView paint event. So it is top left corner of it.



            You where lucky that nothing got broken since you are painting outside of boundingRect.






            share|improve this answer

























            • Thanks for the thorough explanation. I still don't get why I am painting outside of boundingRect; as far as I understand, if QPainter acts in local coordinate and tr is an identity transform, nothing is moved out of the boundingRect...could you explain me, please?

              – JtTest
              Mar 21 at 18:07













            1












            1








            1







            Paint method uses local coordinate system. This means that origin of painter is usually located at top left corner of QGraphicsItem (note this is base class for everything in QGraphicsScene). In case of QGraphicsEllipseItem it must be center of it.



            Apparently this is implemented by transforming QPainter used by QGraphicsView widget when void QWidget::paintEvent(QPaintEvent *event) is processed.



            Simply each QGraphicsItem in QGraphicsScene painted by QGraphicsView transform painter for its needs.



            When you restore identity transformation, you got a painter in state which applies for QGraphicsView paint event. So it is top left corner of it.



            You where lucky that nothing got broken since you are painting outside of boundingRect.






            share|improve this answer















            Paint method uses local coordinate system. This means that origin of painter is usually located at top left corner of QGraphicsItem (note this is base class for everything in QGraphicsScene). In case of QGraphicsEllipseItem it must be center of it.



            Apparently this is implemented by transforming QPainter used by QGraphicsView widget when void QWidget::paintEvent(QPaintEvent *event) is processed.



            Simply each QGraphicsItem in QGraphicsScene painted by QGraphicsView transform painter for its needs.



            When you restore identity transformation, you got a painter in state which applies for QGraphicsView paint event. So it is top left corner of it.



            You where lucky that nothing got broken since you are painting outside of boundingRect.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 21 at 15:43

























            answered Mar 21 at 15:38









            Marek RMarek R

            13.5k22776




            13.5k22776












            • Thanks for the thorough explanation. I still don't get why I am painting outside of boundingRect; as far as I understand, if QPainter acts in local coordinate and tr is an identity transform, nothing is moved out of the boundingRect...could you explain me, please?

              – JtTest
              Mar 21 at 18:07

















            • Thanks for the thorough explanation. I still don't get why I am painting outside of boundingRect; as far as I understand, if QPainter acts in local coordinate and tr is an identity transform, nothing is moved out of the boundingRect...could you explain me, please?

              – JtTest
              Mar 21 at 18:07
















            Thanks for the thorough explanation. I still don't get why I am painting outside of boundingRect; as far as I understand, if QPainter acts in local coordinate and tr is an identity transform, nothing is moved out of the boundingRect...could you explain me, please?

            – JtTest
            Mar 21 at 18:07





            Thanks for the thorough explanation. I still don't get why I am painting outside of boundingRect; as far as I understand, if QPainter acts in local coordinate and tr is an identity transform, nothing is moved out of the boundingRect...could you explain me, please?

            – JtTest
            Mar 21 at 18:07













            0














            Reasoning on Marek's answer, I guess to have found a geometrical explaination. My fault was to inspect painter->matrix() rather than painter->transform(). Indeed, Qmatrix does not manage translation, while painter->transform().m31() and painter->transform().m32() do.



            Substituting the following lines



            qInfo() << painter->transform().m31() << painter->transform().m32();


            in place of /*<--->*/ provides console outputs for the two cases, respectively,



            99 49


            and



            0 0





            share|improve this answer



























              0














              Reasoning on Marek's answer, I guess to have found a geometrical explaination. My fault was to inspect painter->matrix() rather than painter->transform(). Indeed, Qmatrix does not manage translation, while painter->transform().m31() and painter->transform().m32() do.



              Substituting the following lines



              qInfo() << painter->transform().m31() << painter->transform().m32();


              in place of /*<--->*/ provides console outputs for the two cases, respectively,



              99 49


              and



              0 0





              share|improve this answer

























                0












                0








                0







                Reasoning on Marek's answer, I guess to have found a geometrical explaination. My fault was to inspect painter->matrix() rather than painter->transform(). Indeed, Qmatrix does not manage translation, while painter->transform().m31() and painter->transform().m32() do.



                Substituting the following lines



                qInfo() << painter->transform().m31() << painter->transform().m32();


                in place of /*<--->*/ provides console outputs for the two cases, respectively,



                99 49


                and



                0 0





                share|improve this answer













                Reasoning on Marek's answer, I guess to have found a geometrical explaination. My fault was to inspect painter->matrix() rather than painter->transform(). Indeed, Qmatrix does not manage translation, while painter->transform().m31() and painter->transform().m32() do.



                Substituting the following lines



                qInfo() << painter->transform().m31() << painter->transform().m32();


                in place of /*<--->*/ provides console outputs for the two cases, respectively,



                99 49


                and



                0 0






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 21 at 17:35









                JtTestJtTest

                177




                177



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55283613%2fqpainters-setworldtransform-default-behavior%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현