It looks like you're new here. If you want to get involved, click one of these buttons!
Hello,
I am trying to create multiple widgets dynamically in Ruby, but haven't yet figured out a way to identify the widget later which sent the action signal from within the action function. Here is an example code:
def test(buttonName)
puts("Clicked: " + buttonName)
end
dialog = RBA::QDialog::new
vlayout = RBA::QVBoxLayout::new(dialog)
names = Array.new
names.append("button1")
names.append("button2")
names.append("button3")
for i in 0..names.length-1
b = RBA::QPushButton.new(names[i], dialog)
b.objectName = names[i]
b.clicked do
puts(self.to_s)
puts(b.objectName)
end
vlayout.addWidget(b)
end
dialog.show()
I have not found a way to identify the calling widget within the action function, since the self keyword seems to be handled differently in ruby than in python. If there is a way to accomplish this, some feedback would be greatly appreciated.
Comments
Hi!
You could use
QDialogButtonBox
and handle itsclicked
signal for for same purpose.@Sneha_123 your code becomes more readable if you add code block Markdown markup (a single line with triple backticks before and after the code - same as on github for example).
One way to achieve the desired behavior is by putting an annotated receiver object between the signal and your handler:
Matthias