I write code in QT to detect mouse clicks in server and simulate them in client side. I can detect click on buttons as left click and in client, it clicks on position of button but client doesn't realize it as a push button click and related slot doesn't run.
In client it is realized as a left click and mouseReleaseEvent function being ran. how code can detect it as a pushbutton click?
Try to use Qt UI testing:
http://doc.qt.io/qt-5/qtest.html It helpful for generate keyboard and mouse events.
QWidget widget;
QTest::mouseClick(&widget, Qt::LeftButton, Qt::NoModifier, QPoint(clicked,point));
Related
i have an app where i have 2 widgets, one widget shows a video and the other one two buttons as transparent widget lying over the video. Means the widget with the buttons has the focus. When now somebody clicks on the video normally this should emit a signal to open a website in an external browser, but while the other widget has the focus, this signal is not emitted while the click only changes the focus to the video but is not getting the click itself.
is there a way to use the click, to change the focus and catch the click event to open my website?
Georg
I guess you can try the function: setFocusProxy()
video.setFocusProxy(button);
Maybe you can get some help.
I have a slider:
QSlider *mySlider;
And I have a slot wired to it:
void on_mySlider_sliderMoved(int position);
It's wired in setupUI when this is called:
QMetaObject::connectSlotsByName(MainWindow);
When I slide the slider with the mouse, this slot fires correctly and all is well. However, if I click it once with the mouse to "select" it and then use the arrows on the keyboard, I see the slider moving, but the slot never fires.
What am I doing wrong?
QAbstractSlider::sliderMoved signal is emitted when you drag the slider. From the docs: This signal is emitted when sliderDown is true and the slider moves. This usually happens when the user is dragging the slider.
Use QAbstractSlider::valueChanged signal if you want to know every time the value of the slider is changed.
Which SIGNAL is emitted, when pressing the "X" in the top right corner of a Qt Window application?
I have a second QDialog widget beside my MainWindow in my Qt application. And I would like to intercept the press on the "X" in my second QDialog, how?
The QCloseEvent class contains parameters that describe a close event. Close events are sent to widgets that the user wants to close, usually by choosing "Close" from the window menu, or by clicking the X title bar button. They are also sent when you call QWidget::close() to close a widget programmatically.
To ignore it you can call ignore() method:
void YourDialog::closeEvent(QCloseEvent* iEvent)
{
// ignore close event
iEvent->ignore();
}
There is no signal for that, you need to reimplement QWidget::closeEvent() or install an event filter filtering for QCloseEvents.
I have a simple parent widget that reimplements mousePressEvent/mouseReleaseEvent. The parent's child widgets use enterEvent/leaveEvent. When I hover the mouse over the child widgets, leaveEvent/enterEvent executes, but when I click and hold the mouse, mousePressEvent executes, but enterEvent/leaveEvent goes silent (in other words, no click and drag). Any ideas about what could be causing this?
If you press and hold down the mouse button on a widget then that widget grabs mouse events until you release the button. This is not a special feature of Qt, you can find similar behaviour in every other GUI APIs I know.
Take a look at the relevant part of the Qt documentation:
QWidget / Events:
mousePressEvent() is called when a mouse button is pressed while the
mouse cursor is inside the widget, or when the widget has grabbed the
mouse using grabMouse(). Pressing the mouse without releasing it is
effectively the same as calling grabMouse().
void QWidget::grabMouse ():
Grabs the mouse input. This widget receives all mouse events until
releaseMouse() is called; other widgets get no mouse events at all.
how to give control from one window to another by a pushbutton click
Both windows must be part of the same application. Connect the QPushButton clicked signal to a slot on the other window in which activateWindow() is called.