Code for Click on QLabel!?
-
You can use "eventFilter":http://doc.qt.nokia.com/latest/qobject.html#eventFilter for this.
-
Are you trying to make the label work like a button ? In that case ,one easy way is to use QPushButton::setFlat(true) to set the 'flat' property and the button will look like a label.
Or are you completely customizing the QLabel ? -
You can create a class that inherits from QLabel which will implement the following protected function:
@
signals:
void clicked();
protected:
void mousePressEvent ( QMouseEvent * evt);
void mouseReleaseEvent ( QMouseEvent * evt);
@You could set it to emit a clicked signal every time mouseReleaseEvent function is called.
-
You shoud ceate a SLOT to receive the signal from your QLabel. Try this:
@
connect(your_label, SIGNAL(clicked()), this, SLOT(onClicked()));
@ -
There is no clicked signal in QLabel.
-
I don't see the point in using a clickable label; use either a button or a link (with an appropriate style).
-
I agree with fluca1978: why do you want to confuse the user by making something that doesn't hint at being clickable an active component?
-
Sorry, my mistake. But, as fluca said you can use a pushbutton and change the appearance through QSS.
[quote author="Rahul Das" date="1323084178"]There is no clicked signal in QLabel.[/quote]
-
bq.as fluca said you can use a pushbutton and change the appearance through QSS.
QPushButton::setFlat(true) will also do :) (which i have already told^)
-
"Here":http://developer.qt.nokia.com/wiki/How_do_Qlabel_be_clickable you can find the source for 'click'able QLabel
//Off Topic : edit link of previous post is not working for me. :(
Anybody has the same problem ? -
You have the option to make it emit the clicked signal either when mouse gets pressed or when mouse gets release (i prefer the second one). Whatever feels better to you.
-
yea, and there is a "how to":http://developer.qt.nokia.com/wiki/How_do_Qlabel_be_clickable / wiki page to do this saying the same as favoritas37 said :)
[quote author="favoritas37" date="1323012419"]You can create a class that inherits from QLabel which will implement the following protected function:
@
signals:
void clicked();
protected:
void mousePressEvent ( QMouseEvent * evt);
void mouseReleaseEvent ( QMouseEvent * evt);
@You could set it to emit a clicked signal every time mouseReleaseEvent function is called.[/quote]
-
Rahul, i hope you don't mind, i edited the wiki by removing the slot because it caused the signal to be emitted 2 times. And also i changed the name of the new class to ClickableLabel since this is how it is mentioned in the description. Is that ok?
-
Thanks, and thats perfect. :) Two times the same signal, was a careless part anyway.
[quote author="favoritas37" date="1323115942"]Rahul, i hope you don't mind, i edited the wiki by removing the slot because it caused the signal to be emitted 2 times. And also i changed the name of the new class to ClickableLabel since this is how it is mentioned in the description. Is that ok?[/quote] -
hi again
flat property was grate.
:)
thanks to all about help me in this case .
Best regards