QtRuby: get data from TableWidget

Hello!
I’ve started learning QtRuby few days ago so I’ve got newbie question
(not answered by google, though):
There is Qt::TableWidget which I want to use to get data from user.
The question is: how to get all data from from table in array?

On May 8, 5:33 pm, Andrew L. [email protected] wrote:

Hello!
I’ve started learning QtRuby few days ago so I’ve got newbie question
(not answered by google, though):
There is Qt::TableWidget which I want to use to get data from user.
The question is: how to get all data from from table in array?

Posted viahttp://www.ruby-forum.com/.
require ‘Qt4’

app = Qt::Application.new(ARGV)

tableWidget = Qt::TableWidget.new(0, 2)
tableWidget.horizontalHeaderLabels = [“Label1”, “Label2”]
tableWidget.horizontalHeader().setResizeMode(0,
Qt::HeaderView::Stretch)
tableWidget.verticalHeader().hide()
tableWidget.showGrid = false

row = tableWidget.rowCount
tableWidget.insertRow(row)
tableWidget.setItem(row, 0, Qt::TableWidgetItem.new(“data1”))
tableWidget.setItem(row, 1, Qt::TableWidgetItem.new(“data2”))

row = tableWidget.rowCount
tableWidget.insertRow(row)
tableWidget.setItem(row, 0, Qt::TableWidgetItem.new(“data3”))
tableWidget.setItem(row, 1, Qt::TableWidgetItem.new(“data4”))

list = []
for row in 0…tableWidget.rowCount do
for col in 0…tableWidget.columnCount do
tableWidget.setCurrentCell(row, col)
list << tableWidget.currentItem.text
end
end

p list

tableWidget.show
app.exec

Will print:

[“data1”, “data2”, “data3”, “data4”]

– Richard

Thank you, Richard, exactly what i needed!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs