Arrow Keys code and QT buttons

33 views
Skip to first unread message

Bert Mariani

unread,
Apr 8, 2020, 10:28:22 AM4/8/20
to The Ring Programming Language
Hello Mahmoud et ALL

I am trying to get the "Arrow Keys" code when the Up/Down.Left/Right keys are pressed.

Attached are 2  identical ring files
    TestKeyPressChar-NO-QT-Buttons.ring      ### Char code is returned.       The QT section is commented out
    TestKeyPressChar-WITH-QT-Buttons.ring  ### Char code NOT returned.  The QT section is enable

Screen capture shows behaviour.

Question:
     How can the Arrow Keys code be captured / returned  when a program uses QT ?

-----------------------------------------------------
Code
# KeyPress Code: 16777234 = < left
# KeyPress Code: 16777235 = ^ up
# KeyPress Code: 16777237 = v down
# KeyPress Code: 16777236 = > right
Func pWork
myChar = myfilter.getkeycode() 
win.setWindowTitle('KeyPress! : ' + myfilter.getkeycode() +" = "+ char(myChar) )
See "KeyPress Code: "+ myfilter.getkeycode() +" = "+ char(myChar) +nl 
------------------------------------------

QT-Buttons.png




TestKeyPressChar-NO-Qt-Buttons.ring
TestKeyPressChar-WITH-Qt-Buttons.ring

Mahmoud Fayed

unread,
Apr 8, 2020, 12:41:26 PM4/8/20
to The Ring Programming Language
Hello Bert

The Events Filter is an Object

Try installing this object to the buttons too

Greetings,
Mahmoud

Mahmoud Fayed

unread,
Apr 8, 2020, 12:51:40 PM4/8/20
to The Ring Programming Language
Hello Bert

The update to the code will be as in the next screen shot

niceshot.png

Greetings,
Mahmoud

Mahmoud Fayed

unread,
Apr 8, 2020, 12:57:53 PM4/8/20
to The Ring Programming Language
Hello Bert

Also, the next keys are defined automatically by RingQt

Qt_Key_Escape = dec("1000000")    
Qt_Key_Tab = dec("1000001")    
Qt_Key_Backtab  = dec("1000002")    
Qt_Key_Backspace= dec("1000003")
Qt_Key_Return = dec("1000004")
Qt_Key_Enter  = dec("1000005")
Qt_Key_Insert = dec("1000006")    
Qt_Key_Delete = dec("1000007")    
Qt_Key_Pause  = dec("1000008")
Qt_Key_Print    = dec("01000009")
Qt_Key_SysReq    = dec("0100000a")
Qt_Key_Clear    = dec("0100000b")    
Qt_Key_Home    = dec("01000010")
Qt_Key_End    = dec("01000011")
Qt_Key_Left    = dec("01000012")
Qt_Key_Up    = dec("01000013")
Qt_Key_Right    = dec("01000014")
Qt_Key_Down    = dec("01000015")
Qt_Key_PageUp    = dec("01000016")
Qt_Key_PageDown    = dec("01000017")
Qt_Key_Shift    = dec("01000020")
Qt_Key_Control    = dec("01000021")

So, we can direcly use Qt_Key_Up, Qt_Key_Down, Qt_Key_Left & Qt_Key_Right


Greetings,
Mahmoud

Bert Mariani

unread,
Apr 8, 2020, 2:46:22 PM4/8/20
to The Ring Programming Language
Hello Mahmoud

Thank you for the suggestions.

The "installEventsFilter(myFilter)"  inside the Button does not work
It is not part of a Button parameter
      Error (R14) : Calling Method without definition !: installeventsfilter

I have seen these  Word to Code mappings in the docs
     Qt_Key_Left    = dec("01000012")


How can the program know when a User pressed the Arrow Keys ?
The "setKeyPressEvent(pWork)"  does not seem to be generated when QT is in the program.

Mahmoud Fayed

unread,
Apr 8, 2020, 11:57:26 PM4/8/20
to The Ring Programming Language
Hello Bert

Test again, as in the next screen shot

It works on my machine, the QPushButton class inherits from the QWidget class

niceshot.png


Greetings,
Mahmoud

Bert Mariani

unread,
Apr 9, 2020, 7:46:12 AM4/9/20
to The Ring Programming Language
Hello Mahmoud

It worked.
It was my mistake before --- did not pay close enough attention.
I had  typed the line after the closing brace   }   

Thanks again !                        

=====================
FIXED

###>>> WITH QT Buttons     

      width  = 100
      height = 100
       for Row = 1 to size
            for Col = 1 to size
             Button[Row][Col] = new QPushButton(win) {
                  x = (Row-1)*width
                  y = (Col-1)*height
                  setgeometry(x,y,width,height)
                  setclickevent("UserLeftMouse(" + string(Row) + "," + string(Col) + ")")
                  setSizePolicy(1,1) 
                  installEventFilter(myFilter)
               }                  
         next
        next


Snap1.png

Mahmoud Fayed

unread,
Apr 9, 2020, 9:14:20 AM4/9/20
to The Ring Programming Language
Hello Bert

You are welcome :D

Greetings,
Mahmoud
Reply all
Reply to author
Forward
0 new messages