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
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
c++ qt qt5
add a comment |
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
c++ qt qt5
add a comment |
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
c++ qt qt5
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
c++ qt qt5
c++ qt qt5
edited Mar 21 at 17:09
JtTest
asked Mar 21 at 15:11
JtTestJtTest
177
177
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
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
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Mar 21 at 17:35
JtTestJtTest
177
177
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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