generating mouse button click in linux - linux

I'm trying to generate mouse click. I need it to my app, it must simulate mouse click.
QMouseEvent *klik = new QMouseEvent(QEvent::MouseButtonPress, QCursor::pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QCoreApplication::postEvent(this, klik);
QMouseEvent* klik2 = new QMouseEvent(QEvent::MouseButtonRelease, QCursor::pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QCoreApplication::postEvent(this, klik2);
But it not working. It must work on linux, I found many examples for windows but anything for linux not working :(
sorry for my bad english
[EDIT]
I have little problem with QTest. Here are screenshot with compilator errors

Maybe you can use QTest::mouseClick which according to docs simulates mouse clicks.
for example in my MainWindow's constructor:
button = new QPushButton("testPushButton", this);
connect(button, SIGNAL(clicked()), this, SLOT(clickedButton()));
QTest::mouseClick(button, Qt::LeftButton);
And as yankee2905 said you have to add testlib to your .pro file.
In addition I tried to use your code, and when I changed position and receiver of the click it worked just the same as with testlib.
QMouseEvent *klik = new QMouseEvent(QEvent::MouseButtonPress, button->pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QCoreApplication::postEvent(button, klik);
QMouseEvent* klik2 = new QMouseEvent(QEvent::MouseButtonRelease, button->pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QCoreApplication::postEvent(button, klik2);

From your screenshot, looks like you haven't added "testlib" to your qmake file. You'll need that to begin using the QTest components.
Something like this:
qmake test.pro QT+=testlib

Related

Epoll add button not working?

I'm quite new to meteor and I am having some issues.
I am creating an epoll app and here is the link to it: http://epollhouse.meteor.com/
But, when I press the Add question button nothing happens.
Also, for your reference I have posted my source code up onto github: https://github.com/InfamousGamez/epollhouse
Your problem is in epollclient.js
change this: Questions = new Meteor.Collections("questions");
to this: Questions = new Mongo.Collection("questions");

Is there an example for putting the mediaroutebutton on the action bar?

I have it working with the following code on onPrepareMenuOptions but it doesn't work well.
MenuItem mediaRouteItem = menu.findItem(R.id.media_route_button);
mMediaRouteButton = (MediaRouteButton) mediaRouteItem.getActionView();
mMediaRouteButton.setRouteSelector(mMediaRouteSelector);
mDialogFactory = new SampleMediaRouteDialogFactory();
mMediaRouteButton.setDialogFactory(mDialogFactory);
I was hoping to compare it against some code that wasn't written by guessing what to do.
Thanks.
EDIT: I just converted my code to use what is suggested here https://stackoverflow.com/questions/17911796/displaying-the-mediaroutebutton-for-chromecast-in-the-action-bar and had the exact same issues. And if I leave the code with onCreateOptionsMenu then the button is always disabled.

jscrollpane colors

I'm trying to modify the scrollbar colors for jscrollpane.
This didn't work for me:
$('a.athlete_popup_content').click(function(){
$('#box_on_top').append($content); //.athlete class is within $content
$('.athlete').jScrollPane({autoReinitialise: true});
$('.jspVerticalBar').css('width', '10px');
$('.jspTrack').css('background','lightgrey');
$('.jspDrag').css('background','black');
$('.athlete').jScrollPane({autoReinitialise: true});
});
i tried placing athlete class both before and after... it doesn't do anything... also, the second time this runs, the scrollbar doesn't appear at all.
any help?
-=update=-
For the issue where it does not appear correctly the second time, I had to destroy the jsp on close and it started working.
var element = $('.athlete').jScrollPane();
var api = element.data('jsp');
api.destroy();
I was unable to get the colors to work.
I am including the .css initially, but want to change the colors on load. I wasn't able to figure out this issue so I just modified the .css
Thanks!
Your code es working perfectly, as you can see here. If you are calling jScrollPane() on a click event then the tags you are trying to reach (.jspVerticalBar, .jspTrack, .jspDrag) are created after css() calls, then you should use .on() to attach those calls to the event.

Guide.ShowSignIn(1, false) Value not in range exception

In a new Xna game I wroted this:
GamerServicesComponent gsc = new GamerServicesComponent(this);
gsc.Initialize();
Components.Add(gsc);
if(!GamerServicesDispatcher.IsInitialized)
GamerServicesDispatcher.Initialize(Services);
And in the Update method
if (Keyboard.GetState().IsKeyDown(Keys.S))
if (!Guide.IsVisible)
Guide.ShowSignIn(1, false); // true doesn't solve it nor 2 or 4 as paneCount
I'm receiving a
Value does not fall within the expected range.
Anybody?
It seems that Guide.ShowSignIn() can't be used anymore. I Don't know the reason nor if it is really true. But I couldn't get it working with ShowSignIn.
The way I had to login was by pressing the Home button.
The Guide will appear and you can simply follow the Guide to login.
Waiting a few frames before calling Guide.ShowSignIn() works for me. I don't call it until my game has loaded all assets and at least I frame has been rendered.

How to attach mouse event listeners to embedded nsIWebBrowser in C++

I've embedded an nsIWebBrowser in my application. Because I'm just generating HTML for it on the fly, I'm using OpenStream, AppendToStream, and CloseStream to add content. What I need is to add event listeners for mouse movement over the web browser as well as mouse clicks. I've read documentation and tried lots of different things, but nothing I have tried has worked. For instance, the code below would seem to do the right thing, but it does nothing:
nsCOMPtr<nsIDOMWindow> domWindow;
mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
if (!mEventTarget) {
mEventTarget = do_QueryInterface(domWindow);
if (mEventTarget)
mEventTarget->AddEventListener(NS_LITERAL_STRING("mouseover"), (nsIDOMEventListener *)mEventListener, PR_FALSE);
}
Perhaps it isn't working because this is run during initialization, but before any content is actually added. However, if I add it during AppendStream, or CloseStream, it segfaults.
Please tell me a straightforward way to do this.
Well, here's the answer:
nsCOMPtr<nsIDOMEventTarget> cpEventTarget;
nsCOMPtr<nsIDOMWindow> cpDomWin;
m_pWebBrowser->GetContentDOMWindow (getter_AddRefs(cpDomWin));
nsCOMPtr<nsIDOMWindow2> cpDomWin2 (do_QueryInterface (cpDomWin));
cpDomWin2->GetWindowRoot(getter_AddRefs(cpEventTarget));
rv = cpEventTarget->AddEventListener(NS_LITERAL_STRING("mousedown"),
m_pBrowserImpl, PR_FALSE);

Resources