mousepress

How to display the contents in an array by using mouseListener?

那年仲夏 提交于 2021-01-28 13:31:33
问题 I'm doing a program in which there are 8 shapes contained in an array that will be displayed when you click the mouse. I am new to Java and not that familiar with event handlers and listeners. I am trying to make the shapes appear at the location the mouse is clicked at inside the frame yet I am having trouble since the constructor of each shape use 2 Points as its parameter. Here's an example from the code: import MyLibs.Circle; import MyLibs.Rectangle; import MyLibs.Shape; import java.awt

PyQt4: QGraphicsItem mousePressEvent() disables flag ItemIsMovable

試著忘記壹切 提交于 2020-02-05 13:38:52
问题 Here's a bug which I accidently solved it and have no idea why that works. I hope that someone could explain to me the logics behind it. I've reimplmented QGraphicsItem and its mousePressEvent. By doing that the item was no longer movable. Even when trying to call QGraphicsItem.mousePressEvent(self, event) it didn't work. Only when I reimplmented mouseMoveEvent() and mouseReleaseEvent() it finally worked. Code: class LWResizeableItem(QtGui.QGraphicsItem): def __init__(self): super

QLabel OpenCV Image Coordinates in Qt

安稳与你 提交于 2019-12-24 13:23:13
问题 I would like to do manipulations on the image with OpenCV based on mouseClicks. I am using QLabel to display cv::Mat images. Now my problem is with getting the mouse clicks positions with respect to the image. So, I would like (0,0) at topleft corner of the image. Following is my mousePressEvent, but these are not correct co-ordinates. void MainWindow::mousePressEvent( QMouseEvent* ev ) { //This seems to work thanks to Pavel QPoint P = ui->label->mapFrom(this, ev->pos()) //if( ui->label-

QIcon inside combobox

一世执手 提交于 2019-12-11 10:09:10
问题 I want to include a "remove" icon on entries in my QComboBox, but I am having trouble catching the mouse press event. I've tried to catch it on the combobox, and I've tried reimplemting the QIcon class to catch the mousepress there. No dice. Does anybody know how to do this? -D 回答1: I've written code a bit like this, where I wanted to put a tree view inside a combo box and I needed to take an action when the check box on the tree was clicked. What I ended up doing was installing an event

Why always calling mousePressEvent before mouseDoubleClickEvent

99封情书 提交于 2019-12-10 16:27:34
问题 please consider the following code: #include <QWidget> #include <iostream> #include <QApplication> class Widget : public QWidget { public: void mousePressEvent(QMouseEvent* event) { std::cout << "mousePressEvent" < std::endl; } void mouseDoubleClickEvent(QMouseEvent* event) { std::cout << "mouseDoubleClickEvent" << std::endl; } }; int main(int argc, char** argv) { QApplication app(argc, argv); Widget w; w.show(); return app.exec(); } Every time I process double click, the output is:

Getting position of mouse click in a QLabel

好久不见. 提交于 2019-11-27 08:48:50
问题 What is the best (as in simplest) way to obtain the pos of a mousePressedEvent in a QLabel? (Or basically just obtain the location of a mouse click relative to a QLabel widget) EDIT I tried what Frank suggested in this way: bool MainWindow::eventFilter(QObject *someOb, QEvent *ev) { if(someOb == ui->label && ev->type() == QEvent::MouseButtonPress) { QMouseEvent *me = static_cast<QMouseEvent *>(ev); QPoint coordinates = me->pos(); //do stuff return true; } else return false; } However, I