【发布时间】:2011-03-14 10:44:39
【问题描述】:
我认为这个问题最好用代码来描述。我确定解决方案很接近,我只是找不到它。我一直在查看 Qt4 api 以及做教程。到目前为止,这是我的代码:
require 'Qt4'
class PictureCommentForm < Qt::Widget
def initialize(parent = nil)
super()
#setFixedSize(300, 100)
@comment_text = nil
picture = Qt::Label.new()
image = Qt::Image.new('image.jpeg')
picture.pixmap = image
comment = Qt::LineEdit.new()
layout = Qt::VBoxLayout.new()
layout.addWidget(picture)
layout.addWidget(comment)
setLayout(layout)
connect(comment, SIGNAL('returnPressed()'), self, setCommentText(comment.text) )
end
def setCommentText(text)
@comment_text = text
$qApp.quit()
end
end
app = Qt::Application.new(ARGV)
comment_form = PictureCommentForm.new()
comment_form.show()
app.exec
comment_text = comment_form.comment_text
puts "Comment was:\n #{comment_text}"
编辑:感谢那个整数的回答。我想要做的只是一个显示图片和评论的对话框,以便我可以获取该数据。我确实计划用 qt4 制作一个完整的 GUI 版本,但那是以后的事了。
【问题讨论】:
标签: ruby user-interface qt4 user-controls