[Qt-interest] What widget was clicked?
Nikos Chantziaras
realnc at arcor.de
Thu Apr 22 21:17:26 CEST 2010
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.
More information about the Qt-interest-old
mailing list