QtScript documentation? Ability to call functions?

Linux specific forum
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

QtScript documentation? Ability to call functions?

Post by Kukulkan »

Hi,

I wonder where I can find the documentation for QtScript() function?

Also, I can get properties like .visible or .selected but I can't call any functions?

Eg, the StringGadget is internally a QLineEdit gadget (Reference). I can get properties like cursorPosition without any issues. But I can't call any function like setSelection(). Is there a way to call functions, too?

Background: I did a cross platform auto-complete for StringGadget. I made it work on all platforms except Linux with QT because I can't get and set the selection. If I try like this, it returns an error:

Code: Select all

Define gadgID.i = StringGadget(#PB_Any, 10, 10, 380, 26, "Test content")
Debug "Test: " + QtScript(~"gadget("+Str(gadgID.i)+~").setSelection(2,4);")
[13:31:27] [ERROR] JavaScript error: TypeError: Property 'setSelection' of object QLineEdit(0xb51e00) is not a function

But setSelection is a public function of QLineEdit (source).

PS. I know the gtk functions gtk_editable_select_region_() for that. But I'm on QT subsystem.
User avatar
mk-soft
Always Here
Always Here
Posts: 5386
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: QtScript documentation? Ability to call functions?

Post by mk-soft »

I miss that too.
Especially how to get to the parent object.

Code: Select all

;-TOP

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(0)
  dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
  ; Resize Gadgets
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 400, "Test Window", #WinStyle)
    ; MenuBar
    CreateMenu(0, WindowID(0))
    MenuTitle("File")
    
    ; StatusBar
    CreateStatusBar(0, WindowID(0))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(0)
    dy = WindowHeight(0) - StatusBarHeight(0) - MenuHeight()
    StringGadget(0, 10, 10, 200, 25, "String Gadget")
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
    
    Debug qtscript("dump(gadget(0));")
    
    ; Main Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case 0
              Break
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
wombats
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Dec 29, 2011 5:03 pm

Re: QtScript documentation? Ability to call functions?

Post by wombats »

You can use Debug QtScript("dump(gadget(0))") to see all the things available with QtScript, but unfortunately, setSelection isn't in there.

There is a way to do it, but it's a bit more work. You can create a shared object/library with Qt Creator. This opens up a lot of possibilities with Qt. You can use GadgetID() and WindowID() to pass the PureBasic gadgets to the shared library. Here's an example of the C++ code:

Code: Select all

void SetStringSelection(QWidget * PBGadget, int Start, int Finish) {
    QLineEdit *gadget = static_cast<QLineEdit *>(PBGadget);
    gadget->setSelection(Start, Finish);
}
I'm thinking about putting together a library of extra Qt functions. I've got ListIconGadget column header click detection working, but I'm having trouble determining on the C++ side which widget the event is coming from. I have a lot to learn about Qt and C++.
Fred
Administrator
Administrator
Posts: 16664
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: QtScript documentation? Ability to call functions?

Post by Fred »

Interesting way to extends QT support.
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: QtScript documentation? Ability to call functions?

Post by Kukulkan »

wombats wrote: Mon Apr 17, 2023 2:08 pm You can use Debug QtScript("dump(gadget(0))") to see all the things available with QtScript, but unfortunately, setSelection isn't in there.
This is helpful and will safe a lot of time, thanks!

There are a lot of functions exposed, but why are there some missing? Especially the selection functions are of high use? Is there some workaround to call functions not exposed here? Maybe by using another way of gadget access through some parent object/child technique? Or some selection using some sort of document selector for the gadget?
wombats wrote: Mon Apr 17, 2023 2:08 pm You can create a shared object/library with Qt Creator.
An external lib just for calling QT functions on the Linux port of our software is to much overhead. Looks like the Linux people will have to live without AutoComplete :-(
Post Reply