jerous86 / nimqt

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

Problem in Aligment in to GridLayout! #41

Open Martinix75 opened 8 months ago

Martinix75 commented 8 months ago

This is a small piece of code that I am writing (to check the laboratory power supply from PC), but there is a small problem:

import os
import nimqt
import nimqt/qmainwindow
import nimqt/[qpushbutton, qfont, qframe, qlineedit, qgridlayout, qlabel]

nimqt.init()

let
  app = newQApplication(commandLineParams())
  finestra = newQMainWindow()
  wcentale = newQWidget()
  label_1 = newQLabel(Q "15V-5A")
  label_2 = newQLabel(Q "35V-3A")
  label_3 = newQLabel(Q "35V-0.5A")
  led_1 = newQLabel()
  led_2 = newQLabel()
  led_3 = newQLabel()
  bottone_1 = newQPushButton()
  bottone_2 = newQPushButton()
  bottone_3 = newQPushButton()
  frame1 = newQFrame()

label_1.setAlignment(newQFlags(Qt_AlignmentFlag.AlignHCenter))
label_2.setAlignment(newQFlags(Qt_AlignmentFlag.AlignHCenter))
label_3.setAlignment(newQFlags(Qt_AlignmentFlag.AlignHCenter))
bottone_1.setMaximumWidth(20)
bottone_2.setMaximumWidth(20)
bottone_3.setMaximumWidth(20)
frame1.setFrameShape(Box)
frame1.setFrameShadow(Plain)
frame1.setLineWidth(1)
frame1.setMidLineWidth(3)
wcentale.makeLayout:
  -use_object frame_1:
    - newQGridLayout():
      - use_object label_1 at (0,0, setAlignment(newQFlags(Qt_AlignmentFlag.AlignCenter))) # <-- nor work!!!!!!!!
      - use_object label_2 at (0, 1)
      - use_object label_3 at (0, 2)
      - use_object bottone_1 at (1, 0)
      - use_object bottone_2 at (1, 1)
      - use_object bottone_3 at (1, 2)

finestra.setCentralWidget(wcentale)
finestra.show()
discard app.exec()

The problem is that I can't align the widget (I have to align them all) in the center of the table. In the Pythonian version it works as follows:

....
self.Table_10.addWidget(self.Label_20,0,0, Qt.Alignment(Qt.AlignCenter))

Something is missing in the macro of the layout (do I imagine in all layouts) or is something wrong? Hi from Martin A.

jerous86 commented 8 months ago

The macros for a QGridLayout only allows specifying position (and optionally size), but not the alighment. If you really need it, you might use https://doc.qt.io/qt-6/qgridlayout.html#addItem (which should then be used outside the makeLayout macro)

Martinix75 commented 8 months ago

With the "external" table, alignment works, but now I have to see if the Slot-Signal system (somehow) works. BYE and thanks for the continuous updates.