[Kde-bindings] Ruby, sendEvent and KDE

Richard Dale Richard_Dale at tipitina.demon.co.uk
Wed Oct 19 15:38:22 UTC 2005


On Friday 14 October 2005 18:13, Stefan Champailler wrote:
> Dear All,
>
> I'm now facing a problem with sendEvent. The deal is this : I have a
> KDE::HTMLPart in a KDE::MainWindow that I use as a web browser. I'd
> like to simulate a mouse cursor move over on particular place on the
> view of the browser and a mouse click there. For example, open the
> www.kde.org and click on the "announcement" link.
Surely what you actually want to do is to find out which URL is selected under 
the mouse, and open it? I think the KHTMLPart/BrowserExtension apis allow you 
to do that. I don't think you need to simulate mouse events.

-- Richard


> I've written a piece of code that so far can display the browser and
> move the mouse cursor on the link I want :
>
>         p = Qt::Point.new(30,30)
>         p_global = self.mapToGlobal(p)
>         Qt::Cursor.setPos( p_global)
>         KDE::Application::kApplication.processEvents()
>
> The next thing I want to do is the "click". So I do :
>
>         current_widget =
> KDE::Application::kApplication.widgetAt( p_global)
>         mouseEvent( current_widget, Qt::Event::MouseButtonPress, p,
> p_global, Qt::RightButton, 0)
>         mouseEvent( current_widget, Qt::Event::MouseButtonRelease, p,
> p_global, Qt::RightButton, 0)
>
>
> with
>
>     def mouseEvent( target, type, pos, global_pos,button, state)
>         res = Qt::Application::sendEvent( target,
>             Qt::MouseEvent.new( type, target.rect().center(), button,
> state))
>         puts "Cant send event to target" if !res
>     end
>
>
> problem is the sendEvent always returns false and the click never
> occurs.
>
> If I add an event filter I can see that the events I'm sending
> arrives to the widget.
>
> I've been coding ruby/qt/korundum for 2 days so far so I'm quite
> newbie... I'va also checked Qt Test Lib from TrollTech but I think I
> do things like them. The big difference is that to simplify my code
> (i.e. no good reason :)), all this code is part of the MainWindow
> object :
>
> class MainWindow < KDE::MainWindow
>
> which I use like this :
>
> a = KDE::Application.new()
> window = MainWindow.new( "Tutorial - p4", a )
> window.resize( 1200, 800 )
> a.setTopWidget( window)
> window.show
> a.exec
>
>
> help would be much appreciated !
>
> Stefan
>
> _______________________________________________
> Kde-bindings mailing list
> Kde-bindings at kde.org
> https://mail.kde.org/mailman/listinfo/kde-bindings



More information about the Kde-bindings mailing list