Bad rendering of Qrubberband in QGraphicsScene
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have a bad display for q qrubberband thought the wanted coordinates are ok :
class Viewer(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.graphicsView = QtWidgets.QGraphicsView()
self.hbox = QtWidgets.QVBoxLayout()
self.scene = Scene(self)
self.splitter = QtWidgets.QSplitter()
self.splitter.addWidget(self.graphicsView)
self.widget.setLayout(self.hbox)
self.setCentralWidget(self.widget)
I load a pixmap in the scene:
def open_picture(self):
self.scene.setSceneRect(0, 0, self.pixmap.width(), self.pixmap.height())
self.scene.addPixmap(self.pixmap)
self.graphicsView.setScene(self.scene)
self.graphicsView.show()
and I have the scene inheritated from QGraphicsScene mostly tp handle a qrubberband on the scene
class Scene(QtWidgets.QGraphicsScene):
def __init__(self, parent=None):
super(Scene, self).__init__(parent)
def mousePressEvent(self, event):
self.originQPoint = event.scenePos()
self.originQPoint = self.originQPoint.toPoint()
self.currentQRubberBand = QtWidgets.QRubberBand(QtWidgets.QRubberBand.Rectangle)
def mouseMoveEvent(self, event):
self.currentQRubberBand.setGeometry(QtCore.QRect(self.originQPoint, event.scenePos().toPoint()).normalized())
self.currentQRubberBand.show()
def mouseReleaseEvent(self, event):
print(self.items)
self.currentQRubberBand.hide()
self.currentQRect = self.currentQRubberBand.geometry()
print(self.currentQRect)
My problem is the rectangle is displaying on the screen of the my laptop but the coordinate are ok (scene coordinate)
How can I draw the rubberband in the scene correctly without changing the self.currentQRect values ?
python pyqt pyqt5 qgraphicsview qgraphicsscene
add a comment |
I have a bad display for q qrubberband thought the wanted coordinates are ok :
class Viewer(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.graphicsView = QtWidgets.QGraphicsView()
self.hbox = QtWidgets.QVBoxLayout()
self.scene = Scene(self)
self.splitter = QtWidgets.QSplitter()
self.splitter.addWidget(self.graphicsView)
self.widget.setLayout(self.hbox)
self.setCentralWidget(self.widget)
I load a pixmap in the scene:
def open_picture(self):
self.scene.setSceneRect(0, 0, self.pixmap.width(), self.pixmap.height())
self.scene.addPixmap(self.pixmap)
self.graphicsView.setScene(self.scene)
self.graphicsView.show()
and I have the scene inheritated from QGraphicsScene mostly tp handle a qrubberband on the scene
class Scene(QtWidgets.QGraphicsScene):
def __init__(self, parent=None):
super(Scene, self).__init__(parent)
def mousePressEvent(self, event):
self.originQPoint = event.scenePos()
self.originQPoint = self.originQPoint.toPoint()
self.currentQRubberBand = QtWidgets.QRubberBand(QtWidgets.QRubberBand.Rectangle)
def mouseMoveEvent(self, event):
self.currentQRubberBand.setGeometry(QtCore.QRect(self.originQPoint, event.scenePos().toPoint()).normalized())
self.currentQRubberBand.show()
def mouseReleaseEvent(self, event):
print(self.items)
self.currentQRubberBand.hide()
self.currentQRect = self.currentQRubberBand.geometry()
print(self.currentQRect)
My problem is the rectangle is displaying on the screen of the my laptop but the coordinate are ok (scene coordinate)
How can I draw the rubberband in the scene correctly without changing the self.currentQRect values ?
python pyqt pyqt5 qgraphicsview qgraphicsscene
add a comment |
I have a bad display for q qrubberband thought the wanted coordinates are ok :
class Viewer(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.graphicsView = QtWidgets.QGraphicsView()
self.hbox = QtWidgets.QVBoxLayout()
self.scene = Scene(self)
self.splitter = QtWidgets.QSplitter()
self.splitter.addWidget(self.graphicsView)
self.widget.setLayout(self.hbox)
self.setCentralWidget(self.widget)
I load a pixmap in the scene:
def open_picture(self):
self.scene.setSceneRect(0, 0, self.pixmap.width(), self.pixmap.height())
self.scene.addPixmap(self.pixmap)
self.graphicsView.setScene(self.scene)
self.graphicsView.show()
and I have the scene inheritated from QGraphicsScene mostly tp handle a qrubberband on the scene
class Scene(QtWidgets.QGraphicsScene):
def __init__(self, parent=None):
super(Scene, self).__init__(parent)
def mousePressEvent(self, event):
self.originQPoint = event.scenePos()
self.originQPoint = self.originQPoint.toPoint()
self.currentQRubberBand = QtWidgets.QRubberBand(QtWidgets.QRubberBand.Rectangle)
def mouseMoveEvent(self, event):
self.currentQRubberBand.setGeometry(QtCore.QRect(self.originQPoint, event.scenePos().toPoint()).normalized())
self.currentQRubberBand.show()
def mouseReleaseEvent(self, event):
print(self.items)
self.currentQRubberBand.hide()
self.currentQRect = self.currentQRubberBand.geometry()
print(self.currentQRect)
My problem is the rectangle is displaying on the screen of the my laptop but the coordinate are ok (scene coordinate)
How can I draw the rubberband in the scene correctly without changing the self.currentQRect values ?
python pyqt pyqt5 qgraphicsview qgraphicsscene
I have a bad display for q qrubberband thought the wanted coordinates are ok :
class Viewer(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.graphicsView = QtWidgets.QGraphicsView()
self.hbox = QtWidgets.QVBoxLayout()
self.scene = Scene(self)
self.splitter = QtWidgets.QSplitter()
self.splitter.addWidget(self.graphicsView)
self.widget.setLayout(self.hbox)
self.setCentralWidget(self.widget)
I load a pixmap in the scene:
def open_picture(self):
self.scene.setSceneRect(0, 0, self.pixmap.width(), self.pixmap.height())
self.scene.addPixmap(self.pixmap)
self.graphicsView.setScene(self.scene)
self.graphicsView.show()
and I have the scene inheritated from QGraphicsScene mostly tp handle a qrubberband on the scene
class Scene(QtWidgets.QGraphicsScene):
def __init__(self, parent=None):
super(Scene, self).__init__(parent)
def mousePressEvent(self, event):
self.originQPoint = event.scenePos()
self.originQPoint = self.originQPoint.toPoint()
self.currentQRubberBand = QtWidgets.QRubberBand(QtWidgets.QRubberBand.Rectangle)
def mouseMoveEvent(self, event):
self.currentQRubberBand.setGeometry(QtCore.QRect(self.originQPoint, event.scenePos().toPoint()).normalized())
self.currentQRubberBand.show()
def mouseReleaseEvent(self, event):
print(self.items)
self.currentQRubberBand.hide()
self.currentQRect = self.currentQRubberBand.geometry()
print(self.currentQRect)
My problem is the rectangle is displaying on the screen of the my laptop but the coordinate are ok (scene coordinate)
How can I draw the rubberband in the scene correctly without changing the self.currentQRect values ?
python pyqt pyqt5 qgraphicsview qgraphicsscene
python pyqt pyqt5 qgraphicsview qgraphicsscene
edited Nov 22 '18 at 8:34
eyllanesc
86.4k103564
86.4k103564
asked Sep 8 '17 at 9:50
Sylvain PageSylvain Page
8613
8613
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
According to the docs:
QPointF QGraphicsSceneMouseEvent::scenePos() const
Returns the mouse cursor position in scene coordinates.
From the above we can conclude that the point we get is relative to the scene and not to the screen so it is not what we want.
The method to use is screenPos()
:
QPoint QGraphicsSceneMouseEvent::screenPos() const
Returns the mouse cursor position in screen coordinates.
With the above we obtain the following code:
class Scene(QtWidgets.QGraphicsScene):
def __init__(self, parent=None):
super(Scene, self).__init__(parent)
def mousePressEvent(self, event):
self.originQPoint = event.screenPos()
self.currentQRubberBand = QtWidgets.QRubberBand(QtWidgets.QRubberBand.Rectangle)
self.originCropPoint = event.scenePos()
def mouseMoveEvent(self, event):
self.currentQRubberBand.setGeometry(QtCore.QRect(self.originQPoint, event.screenPos()))
self.currentQRubberBand.show()
def mouseReleaseEvent(self, event):
self.currentQRubberBand.hide()
currentQRect = self.currentQRubberBand.geometry()
self.currentQRect = QtCore.QRect(self.originCropPoint.toPoint(), event.scenePos().toPoint())
print(self.currentQRect)
Nope , wiyh screenPos I get a qrubberband on the whole screen. scenePos is what I want and I make a then crop impage and it is OK. The pb is the rendering is not following the mouse cusor (?)
– Sylvain Page
Sep 8 '17 at 11:58
seems, ok (I reimplented my signal and so on to crop the selection in table etc....). Last pb (:p), The qrubberband is 0% transparent whereas it was transluent before (I cannot see anything under the rubberband rect)... I guess I can fix it in the a dedicated method, but it strange. Anyway thanks a lot for screen and scene position
– Sylvain Page
Sep 8 '17 at 19:09
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%2f46113608%2fbad-rendering-of-qrubberband-in-qgraphicsscene%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
According to the docs:
QPointF QGraphicsSceneMouseEvent::scenePos() const
Returns the mouse cursor position in scene coordinates.
From the above we can conclude that the point we get is relative to the scene and not to the screen so it is not what we want.
The method to use is screenPos()
:
QPoint QGraphicsSceneMouseEvent::screenPos() const
Returns the mouse cursor position in screen coordinates.
With the above we obtain the following code:
class Scene(QtWidgets.QGraphicsScene):
def __init__(self, parent=None):
super(Scene, self).__init__(parent)
def mousePressEvent(self, event):
self.originQPoint = event.screenPos()
self.currentQRubberBand = QtWidgets.QRubberBand(QtWidgets.QRubberBand.Rectangle)
self.originCropPoint = event.scenePos()
def mouseMoveEvent(self, event):
self.currentQRubberBand.setGeometry(QtCore.QRect(self.originQPoint, event.screenPos()))
self.currentQRubberBand.show()
def mouseReleaseEvent(self, event):
self.currentQRubberBand.hide()
currentQRect = self.currentQRubberBand.geometry()
self.currentQRect = QtCore.QRect(self.originCropPoint.toPoint(), event.scenePos().toPoint())
print(self.currentQRect)
Nope , wiyh screenPos I get a qrubberband on the whole screen. scenePos is what I want and I make a then crop impage and it is OK. The pb is the rendering is not following the mouse cusor (?)
– Sylvain Page
Sep 8 '17 at 11:58
seems, ok (I reimplented my signal and so on to crop the selection in table etc....). Last pb (:p), The qrubberband is 0% transparent whereas it was transluent before (I cannot see anything under the rubberband rect)... I guess I can fix it in the a dedicated method, but it strange. Anyway thanks a lot for screen and scene position
– Sylvain Page
Sep 8 '17 at 19:09
add a comment |
According to the docs:
QPointF QGraphicsSceneMouseEvent::scenePos() const
Returns the mouse cursor position in scene coordinates.
From the above we can conclude that the point we get is relative to the scene and not to the screen so it is not what we want.
The method to use is screenPos()
:
QPoint QGraphicsSceneMouseEvent::screenPos() const
Returns the mouse cursor position in screen coordinates.
With the above we obtain the following code:
class Scene(QtWidgets.QGraphicsScene):
def __init__(self, parent=None):
super(Scene, self).__init__(parent)
def mousePressEvent(self, event):
self.originQPoint = event.screenPos()
self.currentQRubberBand = QtWidgets.QRubberBand(QtWidgets.QRubberBand.Rectangle)
self.originCropPoint = event.scenePos()
def mouseMoveEvent(self, event):
self.currentQRubberBand.setGeometry(QtCore.QRect(self.originQPoint, event.screenPos()))
self.currentQRubberBand.show()
def mouseReleaseEvent(self, event):
self.currentQRubberBand.hide()
currentQRect = self.currentQRubberBand.geometry()
self.currentQRect = QtCore.QRect(self.originCropPoint.toPoint(), event.scenePos().toPoint())
print(self.currentQRect)
Nope , wiyh screenPos I get a qrubberband on the whole screen. scenePos is what I want and I make a then crop impage and it is OK. The pb is the rendering is not following the mouse cusor (?)
– Sylvain Page
Sep 8 '17 at 11:58
seems, ok (I reimplented my signal and so on to crop the selection in table etc....). Last pb (:p), The qrubberband is 0% transparent whereas it was transluent before (I cannot see anything under the rubberband rect)... I guess I can fix it in the a dedicated method, but it strange. Anyway thanks a lot for screen and scene position
– Sylvain Page
Sep 8 '17 at 19:09
add a comment |
According to the docs:
QPointF QGraphicsSceneMouseEvent::scenePos() const
Returns the mouse cursor position in scene coordinates.
From the above we can conclude that the point we get is relative to the scene and not to the screen so it is not what we want.
The method to use is screenPos()
:
QPoint QGraphicsSceneMouseEvent::screenPos() const
Returns the mouse cursor position in screen coordinates.
With the above we obtain the following code:
class Scene(QtWidgets.QGraphicsScene):
def __init__(self, parent=None):
super(Scene, self).__init__(parent)
def mousePressEvent(self, event):
self.originQPoint = event.screenPos()
self.currentQRubberBand = QtWidgets.QRubberBand(QtWidgets.QRubberBand.Rectangle)
self.originCropPoint = event.scenePos()
def mouseMoveEvent(self, event):
self.currentQRubberBand.setGeometry(QtCore.QRect(self.originQPoint, event.screenPos()))
self.currentQRubberBand.show()
def mouseReleaseEvent(self, event):
self.currentQRubberBand.hide()
currentQRect = self.currentQRubberBand.geometry()
self.currentQRect = QtCore.QRect(self.originCropPoint.toPoint(), event.scenePos().toPoint())
print(self.currentQRect)
According to the docs:
QPointF QGraphicsSceneMouseEvent::scenePos() const
Returns the mouse cursor position in scene coordinates.
From the above we can conclude that the point we get is relative to the scene and not to the screen so it is not what we want.
The method to use is screenPos()
:
QPoint QGraphicsSceneMouseEvent::screenPos() const
Returns the mouse cursor position in screen coordinates.
With the above we obtain the following code:
class Scene(QtWidgets.QGraphicsScene):
def __init__(self, parent=None):
super(Scene, self).__init__(parent)
def mousePressEvent(self, event):
self.originQPoint = event.screenPos()
self.currentQRubberBand = QtWidgets.QRubberBand(QtWidgets.QRubberBand.Rectangle)
self.originCropPoint = event.scenePos()
def mouseMoveEvent(self, event):
self.currentQRubberBand.setGeometry(QtCore.QRect(self.originQPoint, event.screenPos()))
self.currentQRubberBand.show()
def mouseReleaseEvent(self, event):
self.currentQRubberBand.hide()
currentQRect = self.currentQRubberBand.geometry()
self.currentQRect = QtCore.QRect(self.originCropPoint.toPoint(), event.scenePos().toPoint())
print(self.currentQRect)
edited Sep 8 '17 at 12:29
answered Sep 8 '17 at 10:44
eyllanesceyllanesc
86.4k103564
86.4k103564
Nope , wiyh screenPos I get a qrubberband on the whole screen. scenePos is what I want and I make a then crop impage and it is OK. The pb is the rendering is not following the mouse cusor (?)
– Sylvain Page
Sep 8 '17 at 11:58
seems, ok (I reimplented my signal and so on to crop the selection in table etc....). Last pb (:p), The qrubberband is 0% transparent whereas it was transluent before (I cannot see anything under the rubberband rect)... I guess I can fix it in the a dedicated method, but it strange. Anyway thanks a lot for screen and scene position
– Sylvain Page
Sep 8 '17 at 19:09
add a comment |
Nope , wiyh screenPos I get a qrubberband on the whole screen. scenePos is what I want and I make a then crop impage and it is OK. The pb is the rendering is not following the mouse cusor (?)
– Sylvain Page
Sep 8 '17 at 11:58
seems, ok (I reimplented my signal and so on to crop the selection in table etc....). Last pb (:p), The qrubberband is 0% transparent whereas it was transluent before (I cannot see anything under the rubberband rect)... I guess I can fix it in the a dedicated method, but it strange. Anyway thanks a lot for screen and scene position
– Sylvain Page
Sep 8 '17 at 19:09
Nope , wiyh screenPos I get a qrubberband on the whole screen. scenePos is what I want and I make a then crop impage and it is OK. The pb is the rendering is not following the mouse cusor (?)
– Sylvain Page
Sep 8 '17 at 11:58
Nope , wiyh screenPos I get a qrubberband on the whole screen. scenePos is what I want and I make a then crop impage and it is OK. The pb is the rendering is not following the mouse cusor (?)
– Sylvain Page
Sep 8 '17 at 11:58
seems, ok (I reimplented my signal and so on to crop the selection in table etc....). Last pb (:p), The qrubberband is 0% transparent whereas it was transluent before (I cannot see anything under the rubberband rect)... I guess I can fix it in the a dedicated method, but it strange. Anyway thanks a lot for screen and scene position
– Sylvain Page
Sep 8 '17 at 19:09
seems, ok (I reimplented my signal and so on to crop the selection in table etc....). Last pb (:p), The qrubberband is 0% transparent whereas it was transluent before (I cannot see anything under the rubberband rect)... I guess I can fix it in the a dedicated method, but it strange. Anyway thanks a lot for screen and scene position
– Sylvain Page
Sep 8 '17 at 19:09
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%2f46113608%2fbad-rendering-of-qrubberband-in-qgraphicsscene%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