It is currently Tue Nov 12, 2019 8:30 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: QScript - event information?
PostPosted: Thu Jul 19, 2018 3:56 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 498
In freak's example of the QScript command (https://www.purebasic.fr/english/viewtopic.php?p=522895#p522895), is it possible to access the event (QMouseEvent?) to get information about it, like the position of the mouse, etc.?

Specifically, I'd like to detect if the user clicks on the image of a TreeGadget.


Top
 Profile  
Reply with quote  
 Post subject: Re: QScript - event information?
PostPosted: Thu Jul 19, 2018 7:36 pm 
Offline
User
User

Joined: Sat Jun 23, 2018 5:21 pm
Posts: 99
Hello!

1 =TreeGadget
gadget(1).itemEntered(\"2\") ???

If you had access to "QTreeWidgetItem"?!

I am also interested in "Embedding Python in Qt Applications" next to QML, but I do not know yet how to use it with PureBasic.


Top
 Profile  
Reply with quote  
 Post subject: Re: QScript - event information?
PostPosted: Fri Jul 20, 2018 1:23 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 498
ccode wrote:
Hello!

1 =TreeGadget
gadget(1).itemEntered(\"2\") ???

If you had access to "QTreeWidgetItem"?!

Yes, but I'm trying to detect if the user clicks on the item image. I want to change the image when it is clicked, but I don't want it to change if the user clicks on the text or not. On Windows and macOS I'm able to figure it out based on the mouse position, but I can't find a way to get that with Qt.


Top
 Profile  
Reply with quote  
 Post subject: Re: QScript - event information?
PostPosted: Sun Jul 22, 2018 5:26 pm 
Offline
User
User

Joined: Sat Jun 23, 2018 5:21 pm
Posts: 99
Quote:
Yes, but I'm trying to detect if the user clicks on the item image. I want to change the image when it is clicked, but I don't want it to change if the user clicks on the text or not. On Windows and macOS I'm able to figure it out based on the mouse position, but I can't find a way to get that with Qt.


Do you mean something like that?

Code:
For i = 0 To 3
  If CreateImage(i,32,32,24)
    If StartDrawing(ImageOutput(i))
      If i = 0 : Box(0,0,32,32,RGB(255,0,0))
      ElseIf i = 1 : Box(0,0,32,32,RGB(0,255,0))
      ElseIf i = 2 : Box(0,0,32,32,RGB(0,0,255))
      ElseIf i = 3 : Box(0,0,32,32,RGB(255,0,255))
      EndIf
      StopDrawing()
    EndIf
  EndIf
Next i

Structure MPos
  x.d
  y.d
EndStructure

Global TreeMouse.MPos

Global ItemState.b = #False

Runtime Procedure QtSignalHandler()
  If GetGadgetState(1) = 1 And TreeMouse\x < 13 ;Test
    MessageRequester("", "Hallo!")
    If ItemState = #False
      SetGadgetItemImage(1, 1, ImageID(3))
      ItemState = #True
    Else
      SetGadgetItemImage(1, 1, ImageID(1))
      ItemState = #False
    EndIf
  EndIf
EndProcedure

Procedure MouseFrame(win, *mRet.MPos, mx, my, mw, mh)
  Protected mxx, myy
  *mRet\x = 0 : *mRet\y = 0
  mxx = WindowMouseX(win) : myy = WindowMouseY(win)
  If (mxx > mx And mxx < (mw+mx)) And (myy > my And myy < (mh+my))
    *mRet\x = 100 / mw * (mxx-mx)
    *mRet\y = 100 / mh * (myy-my)
  EndIf
EndProcedure

If OpenWindow(0, 0, 0, 320, 250, "FrameGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(0, 10,  10, 300, 50, "Original Text")
  TreeGadget(1, 10, 80, 300, 140)
  AddGadgetItem(1, -1, "Text 1", ImageID(0),0)
  AddGadgetItem(1, -1, "Text 2", ImageID(1),0)
  AddGadgetItem(1, -1, "Text 3", ImageID(2),0)
 
  ; show the TreeGadget object's content
  Debug QtScript("dump(gadget(1).clicked)")
 
  Debug QtScript(~"gadget(1).clicked.connect(function() { runtime.call(\"QtSignalHandler()\"); })")
 
  ; modify the gadget text   
  QtScript(~"gadget(0).text = \"Click on the green box.\"")   
 
  Repeat
    MouseFrame(0, @TreeMouse, 10, 80, 300, 140)
    Debug "X: " + StrD(TreeMouse\x)
    ;Debug "Y: " + StrD(TreeMouse\y)
  Until WindowEvent() = #PB_Event_CloseWindow
EndIf


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye