jerous86 / nimqt

Qt bindings for nim
GNU General Public License v2.0
93 stars 6 forks source link

personal widget declaration #15

Closed Martinix75 closed 1 year ago

Martinix75 commented 1 year ago

HI, I wrote this small test program, and if I write it so the Signal/Slot work correctly:

import os
import nimqt
import nimqt/qdialog
import nimqt/[qpushbutton, qlineedit]

nimqt.init
let app1 = newQApplication(commandLineParams())

let ledit = newQLineEdit(Q"Prima app in Qt")
ledit.setReadOnly(true)
ledit.setDisabled(true)
ledit.setAlignment(newQFlags(Qt_AlignmentFlag.AlignHCenter)) #allinea al centro

inheritQObject(Bottone, QPushButton):
  slot_decl cambia()

let finestra: ptr QDialog = newQDialog() #finestra = qDialog
finestra.makeLayout:
  - use_object ledit
  - newBottone() as bottone: #<-- cosi funziona!!
    setFocus()
    setText(Q"Premi Qui")
    connect(SIGNAL "clicked()", bottone, SLOT "cambia()")

proc cambia(this: ptr Bottone) =
  ledit.setText(Q"Bravo Funziona!!")

finestra.setWindowTitle(Q"Gui-1")
finestra.setGeometry(600, 500, 250, 150)
finestra.show()
discard app1.exec()

However, if it changes it as follows, it is completed correctly, but the Signal/slot does not work:

import os
import nimqt
import nimqt/qdialog
import nimqt/[qpushbutton, qlineedit]

nimqt.init
let app1 = newQApplication(commandLineParams())

let ledit = newQLineEdit(Q"Prima app in Qt")
ledit.setReadOnly(true)
ledit.setDisabled(true)
ledit.setAlignment(newQFlags(Qt_AlignmentFlag.AlignHCenter)) #allinea al centro

inheritQObject(Bottone, QPushButton):
  slot_decl cambia()

let bottone = newBottone() #<-- not work!!!!
bottone.setText(Q"Premi Qui") 

let finestra: ptr QDialog = newQDialog() #finestra = qDialog
finestra.makeLayout:
  - use_object ledit
  - use_object bottone: #<- not work signal/slot
      connect(SIGNAL "clicked()", bottone, SLOT "cambia()") 

proc cambia(this: ptr Bottone) =
  ledit.setText(Q"Bravo Funziona!!")

finestra.setWindowTitle(Q"Gui-1")
finestra.setGeometry(600, 500, 250, 150)
finestra.show()
discard app1.exec()

Maybe I'm wrong something? or cannot be done so? P.S. To my personal taste, I would forget the second way, because so the owners of the widget outside the layout are declared. Innllect the layout (manager) remains much cleaner and easy to read (I repeat my personal taste !!). Thanks and good day from Martin A.

jerous86 commented 1 year ago

I will have a look at it. Just a note that I edited your post to format the code as real code, so it doesn't format it. You can do this by using backticks.

jerous86 commented 1 year ago

I fixed your issue. It was something I had forgotten to implement.