thanks. I try click() and it was OK but could I find a way that doesn't need the name of pushbuttons or other elements? I want to use only x and y position to simulate fake click and get signal of events.
thanks. I try click() and it was OK but could I find a way that doesn't need the name of pushbuttons or other elements? I want to use only x and y position to simulate fake click and get signal of events.
When you used the QTest::mouseClick() method, did you use the one taking a QWidget or the one taking a QWindow?
Cheers,
_
I use this code:
QTest::mouseMove(this,mapToGlobal(QPoint(x,y)));
QTest::mouseClick(this, Qt::LeftButton,0, mapToGlobal(QPoint(x,y)),-1);
"this" is mainwindow. my code shoud be independent of name of widgets like pushbutton.
mapToGlobal doesn't make much sense unless you have ensured that the windows is positioned at 0,0 and thus global/local coordinates being the same.
In either case, you likely need the overload that takes a QWindow, the one that takes a QWidget delivers mouse event to that specific widget.
Cheers,
_
thanks for your quick replies
even when I use qwidget in mousclick function, it doesn't emit a signal!
if (event->button()==Qt::RightButton){
qDebug() << Qt::RightButton << pos();
QPoint Mpush = pos();
QTest::mouseMove(this->m_button,Mpush);
QTest::mouseClick(this->m_button, Qt::LeftButton,0,Mpush,-1);}
in this code, when I Rightclicked on button, the position of cursor places in Mpush and then lift click is simulated. it doesn't emit pushbutton(m_button) signal.
Last edited by NIK-VAJ; 18th February 2016 at 16:48.
So you are trying to simulate a mouse click on "m_button", at x=751, y=327 in "m_button".
Are you certain that the button is really that large?
Is it important for your button where it is clicked?
If not you could just omit the position and it gets clicked in its center.
Cheers,
_
pos() is not position of cursor in the screen?
and how can I find center of poshbutton?
Well, I assume that "this" in your code is a QWidget derived class, which makes pos() most likely this function: QWidget::pos().
Of course if "this" is a class of your own and you have implemented a pos() function that returns the cursor on screen, than that is what it will return.
In that case you need to make sure to map it to the button's coordinate system.
button->rect().center(), but why do you need that?
Cheers,
_
I use this line of code and it emits signal
QTest::mouseClick(this->m_button, Qt::LeftButton,0,m_button->rect().center(),-1);
Clicking the center is the default behavior if you don't specify a position, so you could just call
Qt Code:
QTest::mouseClick(this->m_button, Qt::LeftButton);To copy to clipboard, switch view to plain text mode
Cheers,
_
NIK-VAJ (18th February 2016)
Bookmarks