Closed Martinix75 closed 1 year ago
Hi, the QTableWidgetItem
class can be found in qtablewidget.
I don't know/recall why it's not in its own module, but I might be due to recursive module imports.
ok tahnks! after I try and I will be able to tell you if it works and how :), now boring unnecessary meetings: (( For now thanks!
done a test ... and something seems to me not to work !!!
import std/[os, random, tables]
import nimqt
import nimqt/qdialog
import nimqt/[qpushbutton, qtablewidget, qgridlayout,qboxlayout, qlabel]
proc aggiornaTabella(tab: ptr QTableWidget; xmax, ymax: cint) =
echo("aggiorno......")
tab.setColumnCount(xmax)
tab.setRowCount(ymax)
for x in countup(0, xmax):
for y in countup(0, ymax):
var item = newQTableWidgetItem(cint(7)) #now only "7". after rnd number float or Qstring(?)!!!
tab.setItem(cint(y), cint(x), item) # --> ERROR!!!
const
xMax = 7
yMax = 10
var
numeri = initTable[array[0..1, int], float]() #inizializza il dizionario pe ri valori.
formato = {"separatore": ",", "decimali": ".", "noddec": "2", "rossonegativo": "false"}.toTable #provvisorio fore usa type!!
for x in countup(0, xMax):
for y in countup(0, yMax):
numeri[[x ,y]] = (10000*rand(1.0)) - 5000
echo numeri
nimqt.init
let app1 = newQApplication(commandLineParams())
let tabella1 = newQtableWidget()
let bottone1 = newQPushButton(Q "Modale")
let bottone2 = newQPushButton(Q "Modless")
#let bottone3 = newQPushButton(Q "Live")
let finestra: ptr QDialog = newQDialog() #finestra = qDialog
finestra.makelayout:
- useObject tabella1
- newQWidget():
- newQHBoxLayout():
- useObject bottone1
- useObject bottone2
aggiornaTabella(tab=tabella1, xmax=xMax, ymax=yMax)
finestra.resize(750, 400)
finestra.show()
discard app1.exec()
the error is:
/home/andrea/ownCloud/In_Sviluppo/NimQt/Gui2_7_stadardDialog/Gui2_7_madre.nim(13, 9) Error: type mismatch: got <ptr QTableWidget, cint, cint, QTableWidgetItem>
but expected one of:
proc setItem(this: ptr QTableWidget; row: cint; column: cint;
item: ptr QTableWidgetItem)
first type mismatch at position: 4
required type for item: ptr QTableWidgetItem
but expression 'item' is of type: QTableWidgetItem
expression: setItem(tab, cint(y), cint(x), item)
In addition, I suspect, that when in "var Item = newqtablewidgetitis (cint (7))" I will use a float number, it won't work !! (Try to put 7.7 instead of 7 !!), but in the tables it should also be possible to use "float" but in the proc declaration I do not see this possibility. As usual, it can be my mistake and not of the library :)
Good day from Andrea
I tried to make this modification in the procedure .. not from compilation error, but writes strange things ...
proc aggiornaTabella(tab: ptr QTableWidget; xmax, ymax: cint) =
echo("aggiorno......")
tab.setColumnCount(xmax)
tab.setRowCount(ymax)
let item = newQTableWidgetItem(Q "yep") #now only "7". after rnd number float!!!
for x in countup(0, xmax):
for y in countup(0, ymax):
tab.setItem(cint(y), cint(x), item.unsafeaddr()) # --> now strange mesage (with unsafeAddr()!
error:
.....
QTableWidget: cannot insert an item that is already owned by another QTableWidget
QTableWidget: cannot insert an item that is already owned by another QTableWidget
QTableWidget: cannot insert an item that is already owned by another QTableWidget
QTableWidget: cannot insert an item that is already owned by another QTableWidget
QTableWidget: cannot insert an item that is already owned by another QTableWidget
QTableWidget: cannot insert an item that is already owned by another QTableWidget
QTableWidget: cannot insert an item that is already owned by another QTableWidget
I hope you can help you understand the problem (or where I'm wrong) !!
Hi, I just pushed a commit that makes QTableWidgetItem
a ptr
. WIth that change, your first example works for me.
Always very kind and super efficient! I try this afternoon (now I pretend to work). Yes, the first example was the important one the second was so to test! Thank you
import std/[os, random, tables]
import nimqt
import nimqt/qdialog
import nimqt/[qpushbutton, qtablewidget, qgridlayout,qboxlayout, qlabel]
proc aggiornaTabella(tab: ptr QTableWidget; xmax, ymax: cint; num: Table[array[0..1, int], int]) =
echo("aggiorno......")
tab.setColumnCount(xmax)
tab.setRowCount(ymax)
for x in countup(0, ymax-1):
for y in countup(0, xmax-1):
let item = newQTableWidgetItem(Q $num[[x,y]])
tab.setItem(cint(x), cint(y), item)
const
xMax = 7
yMax = 10
var
numeri = initTable[array[0..1, int], int]() #inizializza il dizionario pe ri valori.
formato = {"separatore": ",", "decimali": ".", "noddec": "2", "rossonegativo": "false"}.toTable #provvisorio fore usa type!!
cancellami=1
for x in countup(0, yMax-1):
for y in countup(0, xMax-1):
#numeri[[x ,y]] = (10000*rand(1.0)) - 5000
numeri[[x ,y]] = cancellami
cancellami.inc()
echo numeri
nimqt.init
let app1 = newQApplication(commandLineParams())
let tabella1 = newQtableWidget()
let bottone1 = newQPushButton(Q "Modale")
let bottone2 = newQPushButton(Q "Modless")
#let bottone3 = newQPushButton(Q "Live")
let finestra: ptr QDialog = newQDialog() #finestra = qDialog
finestra.makelayout:
- useObject tabella1
- newQWidget():
- newQHBoxLayout():
- useObject bottone1
- useObject bottone2
aggiornaTabella(tab=tabella1, xmax=xMax, ymax=yMax, num=numeri)
finestra.resize(750, 400)
finestra.show()
discard app1.exec()
wow! run perfectly!! At least it seems to be always convenient in qstring! (int, float etc.) thnks by Andrea :))
Here I am again !!! Tonight I was trying to play with the tables (QTableWidget) all right until I had to insert values. These values (at least one way I believe) is to use "QTablewidgetItem" which, however, in the "Nimqt" lib I don't seem to see it! or did the timetable have escaped me? If it is missing, I think it is a good thing to add it, because I think it is necessary to fill the tables.
Good day from Andrea