Page 1 of 1
QtScript documentation? Ability to call functions?
Posted: Mon Apr 17, 2023 12:37 pm
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.
Re: QtScript documentation? Ability to call functions?
Posted: Mon Apr 17, 2023 2:07 pm
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()
Re: QtScript documentation? Ability to call functions?
Posted: Mon Apr 17, 2023 2:08 pm
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++.
Re: QtScript documentation? Ability to call functions?
Posted: Mon Apr 17, 2023 2:51 pm
by Fred
Interesting way to extends QT support.
Re: QtScript documentation? Ability to call functions?
Posted: Mon Apr 17, 2023 3:03 pm
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
