[Qt-interest] What widget was clicked?

Eckhard Jokisch e.jokisch at orange-moon.de
Fri Apr 23 08:59:38 CEST 2010


Nikos Chantziaras schrieb:
> On 04/22/2010 09:55 PM, Keiver Hdez Fdez wrote:
>   
>> Hello folks, I have some widget added dynamically, like this:
>>
>> QWidget * uno = new QWidget(parent);
>> uno->setStyleSheet("background: yellow");
>> QWidget * dos = new QWidget(parent);
>> dos->setStyleSheet("background: blue");
>> QWidget * tres = new QWidget(parent);
>> tres->setStyleSheet("background: white");
>>
>> ui->horizontalLayout->addWidget(uno);
>> ui->horizontalLayout->addWidget(dos);
>> ui->horizontalLayout->addWidget(tres);
>>
>> How do I know what was the widget the user clicked?
>>     
>
> By using a QWidget subclass that can tell you this.  Like a QPushButton, 
> or your own custom subclass that reimplements mousePressEvent() and/or 
> mouseReleaseEvent() and emits some kind of signal when a click is 
> detected.  You then catch that signal, just like you do if you use a 
> QPushButton.
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>   
How do you connect the signals to slots?
If you handcode this you could as well create different slots for every
widget, set some value in this slot and call a slot that is shared by
all widgets equally if needed.

Or do I miss something?




More information about the Qt-interest-old mailing list