jerous86 / nimqt

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

qdialoagBox #13

Closed Martinix75 closed 1 year ago

Martinix75 commented 1 year ago

Good evening, I'm playing a little with Nimqt and I must say it's fun. But I have a small problem with "qdiaogbox" that I didn't understand very well what to pass. For now I have made so I am attaching my program and if you make me understand the error I will be very happy :) good evening!

import os import nimqt import nimqt/[qlabel, qpushbutton, qspinbox, qicon] import nimqt/[qwidget, qboxlayout, qgridlayout, qdialogbuttonbox]

nimqt.init

let pwmApp = newQApplication(commandLineParams()) let lab1 = newQLabel(Q"Set PWM") let sbx1 = newQSpinBox() sbx1.setRange(0,100) sbx1.setsuffix(Q"%") let lab2 = newQLabel(Q"Set Time") let sbx2 = newQSpinBox() sbx2.setSuffix(Q" Min") sbx2.setMinimum(0)

let sbx3 = newQSpinBox() sbx3.setSuffix(Q" Sec") sbx3.setRange(0, 59)

let icona = newQIcon(Q"eco.png")

let finestra: ptr QWidget = newQWidget() finestra.makeLayout: #cosi sembra un layout verticale...

finestra.setWindowTitle(Q"TestPWM") finestra.setGeometry(160, 140, 300, 100) finestra.setWindowIcon(icona) finestra.show() discard pwmApp.exec()

Thanks for your help by A.Martin

jerous86 commented 1 year ago

I think the following is what you want to do? I don't get the buttons, but not sure how they work in Qt.

let finestra: ptr QWidget = newQWidget()
finestra.makeLayout: #cosi sembra un layout verticale...
    - newQWidget():
        - newQHBoxLayout():
            - use_object lab1
            - use_object sbx1
    - newQWidget():
        - newQHBoxLayout():
            - use_object lab2
            - use_object sbx2
            - use_object sbx3
    - newQDialogButtonBox(newQFlags(Yes)|newQFlags(No), finestra) #<-- ?????????
Martinix75 commented 1 year ago

So not a mistake in compilation, but I don't see the buttons (not even me) I work on it on a while and I see if I solve, for now thanks!

Martinix75 commented 1 year ago

I understood the problem !!! The problem is in the "qdialobuttonbox.nim" file. Specifically in the "Enum" wrong: [QDialogButtonBox_StandardButton* {.header:headerFile,importcpp:"QDialogButtonBox::StandardButton".} = enum NoButton = 0, Ok = 0x1, Save = 0x2, SaveAll = 0x3, Open = 0x4, Yes = 0x5, YesToAll = 0x6, No = 0x7, NoToAll = 0x8, Abort = 0x9, Retry = 0xa, Ignore = 0xb, Close = 0xc, Cancel = 0xd, Discard = 0xe, Help = 0xf, Apply = 0x10, Reset = 0x11, RestoreDefaults = 0x12, FirstButton = 0x13, LastButton = 0x14]

I corrected it (only partially .. for testing, in this way ..) QDialogButtonBox_StandardButton* {.header:headerFile,importcpp:"QDialogButtonBox::StandardButton".} = enum NoButton = 0, Ok = 0x400, Yes = 0x4000, No = 0x10000

as indicated in the following table https://doc.qt.io/qt-6/qdialogbuttonbox.html

By putting the correct numbers in Enum the buttons appear!

I did the "fork" of your project, if I can (time permitting) I see if I can modify and make a Commit. Hi from Andrea

jerous86 commented 1 year ago

Thank you very much for finding the solution!

Your patch is correct, but the issue was in the code that generated the bindings (and so there are many more enums that were not correct), while yours only fixes a single file, so I will not pull it. But your help is much appreciated! :)