Results 1 to 2 of 2

Thread: Getting Data from a javascript object OR embedding object in QT widget

  1. #1
    Join Date
    Dec 2018
    Qt products
    Unix/X11 Windows

    Default Getting Data from a javascript object OR embedding object in QT widget

    Hi! My high level problem is this:

    I can generate a snazzy interactive network graph with (a python package)
    I can generate fancy controls and buttons with QT

    So far, I can't get them to communicate with each other.

    Solution Attempt 1:

    I generate the pyviz object and write to html.
    then load the html in my widget:
    (into a QtWebEngineWidgets.QWebEngineView)
    self.load(QtCore.QUrl().fromLocalFile(myfile.html) )

    that works great... but swimming through all the methods I couldn't find how to access the data (it's embedded in a javascript script object)

    Solution Attempt 2:

    I can't find a way to load the python object itself into a widget (bypassing write to html)

    Any thoughts ideas? Let me know if you need more info.

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 655 Times in 645 Posts
    Qt products
    Windows Android

    Default Re: Getting Data from a javascript object OR embedding object in QT wid

    So far, I can't get them to communicate with each other.
    I presume you are using PyQt for the GUI, right? Almost all Qt GUI widgets will generate one or more signals when you interact with them (like clicking with the mouse, typing, etc.). In order to do anything with those signals you have to write slots in your own GUI containers (composite QWidgets like QDialog, QFrame, etc.) and connect those to the objects and their signals.

    I don't know much about, but when you say it is "interactive" I assume you mean that you can click on nodes or edges and can cause something to happen. Internally, there should be methods you can call to simulate these kinds of interactions programmatically. I would guess there are also Python events that get generated through a user interaction which you can trap programmatically.

    So for the Qt GUI to communicate to the Python object, your slots will need to call the methods that result in the change you want. To go the other way, the events that result from a user interaction need to be trapped and relayed to the Qt side by turning them into Qt signals emitted by your GUI.

    Here's a link to a stackoverflow discussion of how to connect matplotlib and Qt. as well as an example on the matplotlib site.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Access QML Object between QML & Javascript
    By scgrant327 in forum Qt Quick
    Replies: 9
    Last Post: 9th September 2016, 13:49
  2. TypeError: Object [object Object] has no method 'sendData'
    By TheIndependentAquarius in forum Qt Quick
    Replies: 2
    Last Post: 30th November 2013, 05:54
  3. Access Object Created by javascript in qml
    By alizadeh91 in forum Qt Quick
    Replies: 6
    Last Post: 23rd February 2012, 15:06
  4. Replies: 9
    Last Post: 29th November 2010, 12:12
  5. Mapping JavaScript object to QT (and vice versa)
    By leoalvesmachado in forum Newbie
    Replies: 2
    Last Post: 30th June 2010, 19:00


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.