jerous86 / nimqt

Qt bindings for nim
GNU General Public License v2.0
101 stars 7 forks source link

Maybe a problem in the toolbar? #40

Open Martinix75 opened 8 months ago

Martinix75 commented 8 months ago

Today I tried to write this code, but if I pray the button (qpushbutton) does not print anything to console: am I doing something wrong?

import os
import nimqt
import nimqt/qmainwindow
import nimqt/[qpushbutton, qlineedit, qfiledialog, qspinbox]
import nimqt/tools/toolbar

nimqt.init 
let app1 = newQApplication(commandLineParams())
let finestra: ptr QMainWindow = newQMainWindow() 
let centrale = newQWidget()

let ledit = newQLineEdit(Q"Prima app in Qt MainWindow")
ledit.setReadOnly(true)
ledit.setDisabled(true)
ledit.setAlignment(newQFlags(Qt_AlignmentFlag.AlignHCenter)) 
inheritQObject(Bottone, QPushButton):
  slot_decl cambia()
proc cambia(this: ptr Bottone) =
  ledit.setText(Q"Hello World!!")
let bottone = newBottone() 
bottone.setText(Q"Premi Qui")

let toolbar1=finestra.addToolbar(Q"Toolbar 1")
toolbar1.makeToolbar:
  - "Apri":
    setIcon(newQIcon(Q "Icons/open.png"))
    handleTriggered():
      let nomeFile = finestra.static_QFileDialog_getOpenFileName()
      ledit.setText(nomeFile)
  - "Chiudi":
    setIcon(newQIcon(Q "Icons/close.png"))
    handleTriggered():
      quit(0)
  - newQPushButton(Q "Premi!"):
    setEnabled(true)
    handleTriggered():
      echo "-------- hellooo ----------" # <--Don't print this message (don't take the call ??)

centrale.makeLayout:
  - use_object ledit
  - use_object bottone:
      connect(SIGNAL "clicked()", bottone, SLOT "cambia()") 

finestra.setCentralWidget(centrale)
finestra.setWindowTitle(Q"MainWindow")
finestra.setGeometry(600, 500, 250, 150)
finestra.setWindowIcon(newQIcon(Q "Icons/panoratux.png"))
finestra.show()
discard app1.exec()

he button appears regularly in the toolbar, but by pressing not printing "--- Hello-", is it a bug, or am I using the macro badly? Good day from Martin A.

jerous86 commented 8 months ago

I haven't tried it yet, but maybe you could try using a QToolButton?

Martinix75 commented 8 months ago

no!!! I didn't try that, but I do it as soon as I have some time (I am also from the club I miss time :))