Merge two pieces of code
-
@john_hobbyist
But you don't tell me, so you want me to guess?Does it hit the
self.selection.show()
? Does it hit the move code? What is your usage of Pythonis
instead of==
inif self.mode is "drag_lower_right"
?I leave it to you now.
-
@JonB Sorry! I updated the right code! Please see above 2-3 posts..
When I press the mouse button it goes: 56, 57,58, 59, 62, 63, 56, 57,58, 59, 62, 63....
When I move the mouse, it goes 71, 72, 73, 74, 77, 71, 72, 73, 74, 77...
Either I have loaded an image or not! -
@john_hobbyist
I don't know.self.lower_right = QtCore.QPoint(event.pos()) self.upper_left = QtCore.QPoint(event.pos()) self.selection.setGeometry(QtCore.QRect(self.upper_left, self.lower_right).normalized())
Are the coordinates of
event.pos()
correct forsetGeometry()
? Start by getting some visible rubber band, e.g. put suitable constants in there instead of relying on mouse positions? -
@john_hobbyist did you try to just get the rubber band stuff working on a minimal widget ?
You can then apply that knowledge to your more complex application.
-
-
@john_hobbyist
Hi
Progress :) \o/Check for RubberbandEnhancedLabel (if you use it still ) what parent you assign to it
when you create it. -
@mrjj You mean this:
label = RubberbandEnhancedLabel()
but I do not use it. I have it as comment from previous code. Basically the whole unused/commented code is this:
app = QtWidgets.QApplication([]) screen_pixmap = QScreen.grabWindow (self, win_id, left, top, width, height) window = QtGui.QWidget() layout = QtWidgets.QVBoxLayout(window) label = RubberbandEnhancedLabel() label.setPixmap(screen_pixmap) layout.addWidget(label) geometry = app.desktop().availableGeometry() window.setFixedSize(geometry.width(), geometry.height())
which I do not use (copied from one of the sources above...). Should I use something from here?
-
@john_hobbyist
Hi
So what IS the blue rectangle then ?Check the parent where you create it.
-
@john_hobbyist
Yes but its hard to know what you currently have.
So the blue rectangle is a QRubberband ?So there place where you create it, what is used as the parent.
It kinda seems like the Toolbar as else it would not clip to it.is self.selection the RubberBand ?
-
@john_hobbyist
Hi
Hmm The reason its up in the Toolbar seems not to be be related to parentclass MyMplCanvas(mpl_qt.FigureCanvasQTAgg):
....
self.selection = QtWidgets.QRubberBand(QtWidgets.QRubberBand.Rectangle, self)I assume here self is MyMplCanvas and as far as we know MyMplCanvas is the class that draw the image.
So the Rubberband works, but cant be dragged outside that little area ?
-
@john_hobbyist
Ok. That is bizarre as that sounds like it is inside the toolbar.
and the mouseXXX functions are under the MyMplCanvas ?I don't get this as then it should not work if it's placed in toolbar as the mouse events go into
MyMplCanvas.unde this line
self.selection = QtWidgets.QRubberBand(QtWidgets.QRubberBand.Rectangle, self)is it possible to
print (self) ?Im not sure if it just shows the address.
-
@john_hobbyist
Hi
Oh that actually worked. the print(self)
so the parent really is MyMplCanvas.So how does it show the blue rect ?
You click on the Canvas and it appears up there ?
-
@mrjj Yes I click on the large area (where the images are depicted) and I see the result as I depicted in the figure above, BUT it never completes the operation, meaning that as I move it, the rectangle keeps changing on that small area..
-
@john_hobbyist
Ok. since it seems it should be in the Canvas, I would put some print() underself.selection.setGeometry(QtCore.QRect(self.upper_left, self.lower_right).normalized())
in mouseMove and inspect the values and see
like
print( QtCore.QRect(self.upper_left, self.lower_right).normalized() )and see what values it sets. Maybe that can give a hint.
-
@john_hobbyist said in Merge two pieces of code:
class RubberbandEnhancedLabel(QtGui.QLabel): def __init__(self, parent=None): QtGui.QLabel.__init__(self, parent) self.selection = QtGui.QRubberBand(QtGui.QRubberBand.Rectangle, sel
Your rubber band should be constrained within your
RubberbandEnhancedLabel
. On your screenshot, where exactly do you claim thatRubberbandEnhancedLabel
to be? Perhaps you should show the same screenshot but with an image in the label so we can see?And what values does
self.upper_left, self.lower_right
have for the rubberband shown in the screenshot? -
@mrjj This the value for the upper left corner inside the canvas that images are depicted:
PyQt5.QtCore.QRect(8, 0, 25, 69)
And this is the value for the lower right corner:
PyQt5.QtCore.QRect(32, 68, 506, 543)
(with some error). So the values are changing...
And when I go inside the area of the toolbox in upper left area, I get this:
Widget::paintEngine: Should no longer be called QPainter::begin: Paint device returned engine == 0, type: 1 QPainter::end: Painter not active, aborted
which I get it repeatedly as I change tool icon...