0

I am following examples all over, including this SO answer: https://stackoverflow.com/a/14114878/274354

My code falls over when trying to create the ListWidgetItem with the icon with this message:

/usr/lib64/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2642:in `initialize': unresolved constructor call Qt::ListWidgetItem (ArgumentError)

Here is the code:

require 'Qt4'

app = Qt::Application.new(ARGV)

# Main Window
widget = Qt::Widget.new()

# Create icon from a file, and create a list widget item from the icon
icon = Qt::Icon.new("/home/user1/Pictures/testimage.JPG")
item = Qt::ListWidgetItem.new(icon) #<-- Falls over here

# Create a list widget
list = Qt::ListWidget.new(widget)

# Set the icon size for the list
iconsize = Qt::Size(40,40)
list.setIconSize(iconsize)

# Add the list item with the image
list.addItem(item)

widget.show()

app.exec()
Community
  • 1
  • 1
mydoghasworms
  • 18,233
  • 11
  • 61
  • 95

1 Answers1

0

The error message is pretty clear. You're using QListWidgetItem constructor with invalid arguments. There is no QListWidgetItem constructor that accepts icon only. You need to pass item text as the second argument. See QListWidgetItem documentation.

Pavel Strakhov
  • 39,123
  • 5
  • 88
  • 127