ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
Re: QtRuby: get data from TableWidget
by Richard.J.Dale@Gmail.Com other posts by this author
May 8 2008 12:45PM messages near this date
QtRuby: get data from TableWidget | Re: QtRuby: get data from TableWidget
On May 8, 5:33 pm, Andrew Lepyokhin <la.bi...@[...].com>  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
Thread:
Andrew Lepyokhin
Richard.J.Dale@Gmail.Com
Andrew Lepyokhin

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved