def test_link_handling(self): noKeys = QtCore.Qt noButton = QtCore.Qt.MouseButton(0) noButtons = QtCore.Qt.MouseButtons(0) noModifiers = QtCore.Qt.KeyboardModifiers(0) MouseMove = QtCore.QEvent.MouseMove QMouseEvent = QtGui.QMouseEvent w = ConsoleWidget() cursor = w._get_prompt_cursor() w._insert_html(cursor, '<a href="http://python.org">written in</a>') obj = w._control tip = QtGui.QToolTip self.assertEqual(tip.text(), u'') # should be somewhere else elsewhereEvent = QMouseEvent(MouseMove, QtCore.QPoint(50, 50), noButton, noButtons, noModifiers) w.eventFilter(obj, elsewhereEvent) self.assertEqual(tip.isVisible(), False) self.assertEqual(tip.text(), u'') # should be over text overTextEvent = QMouseEvent(MouseMove, QtCore.QPoint(1, 5), noButton, noButtons, noModifiers) w.eventFilter(obj, overTextEvent) self.assertEqual(tip.isVisible(), True) self.assertEqual(tip.text(), "http://python.org") # should still be over text stillOverTextEvent = QMouseEvent(MouseMove, QtCore.QPoint(1, 5), noButton, noButtons, noModifiers) w.eventFilter(obj, stillOverTextEvent) self.assertEqual(tip.isVisible(), True) self.assertEqual(tip.text(), "http://python.org")
def drawLabelAtMouse(self, qp): # Nothing to do without a highlighted object if not self.highlightObj: return # Nothing to without a mouse position if not self.mousePosOrig: return # Save QPainter settings to stack qp.save() # That is the mouse positiong mouse = self.mousePosOrig # Will show zoom showZoom = self.zoom and not self.image.isNull() and self.w and self.h # The text that is written next to the mouse mouseText = self.highlightObj.label # Where to write the text # Depends on the zoom (additional offset to mouse to make space for zoom?) # The location in the image (if we are at the top we want to write below of the mouse) off = 36 if showZoom: off += self.zoomSize / 2 if mouse.y() - off > self.toolbar.height(): top = mouse.y() - off btm = mouse.y() vAlign = QtCore.Qt.AlignTop else: # The height of the cursor if not showZoom: off += 20 top = mouse.y() btm = mouse.y() + off vAlign = QtCore.Qt.AlignBottom # Here we can draw rect = QtCore.QRect() rect.setTopLeft(QtCore.QPoint(mouse.x() - 200, top)) rect.setBottomRight(QtCore.QPoint(mouse.x() + 200, btm)) # The color qp.setPen(QtGui.QColor('white')) # The font to use font = QtGui.QFont("Helvetica", 20, QtGui.QFont.Bold) qp.setFont(font) # Non-transparent qp.setOpacity(1) # Draw the text, horizontally centered qp.drawText(rect, QtCore.Qt.AlignHCenter | vAlign, mouseText) # Restore settings qp.restore()
def test_droplist_completer_mousepick(self): leftButton = QtCore.Qt.LeftButton w = CompletionWidget(self.console) w.show_items(self.text_edit.textCursor(), ["item1", "item2", "item3"]) QTest.mouseClick(w.viewport(), leftButton, pos=QtCore.QPoint(19, 8)) QTest.mouseRelease(w.viewport(), leftButton, pos=QtCore.QPoint(19, 8)) QTest.mouseDClick(w.viewport(), leftButton, pos=QtCore.QPoint(19, 8)) self.assertEqual(self.text_edit.toPlainText(), "item1") self.assertFalse(w.isVisible())
def mousePressEvent(self, event): try: if self.scene.isUnderMouse(): self.photoClicked.emit(QtCore.QPoint(event.pos())) # keep the default behaviour super(MyQGraphicsView, self).mousePressEvent(event) except Exception as e: print(e)