Code for Click on QLabel!?
-
wrote on 4 Dec 2011, 13:49 last edited by
Hi
I want to generate code for Clicked on QLabel event such as QpushButton
but QLable just has these events :
@
LinkActivated();
linkHovered();
destroyed();
customContextMenuRequested();
@
can i do it? -
wrote on 4 Dec 2011, 14:35 last edited by
You can use "eventFilter":http://doc.qt.nokia.com/latest/qobject.html#eventFilter for this.
-
wrote on 4 Dec 2011, 14:49 last edited by
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 ? -
wrote on 4 Dec 2011, 15:26 last edited by
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.
-
wrote on 5 Dec 2011, 10:32 last edited by
You shoud ceate a SLOT to receive the signal from your QLabel. Try this:
@
connect(your_label, SIGNAL(clicked()), this, SLOT(onClicked()));
@ -
wrote on 5 Dec 2011, 11:22 last edited by
There is no clicked signal in QLabel.
-
wrote on 5 Dec 2011, 11:38 last edited by
I don't see the point in using a clickable label; use either a button or a link (with an appropriate style).
-
wrote on 5 Dec 2011, 11:57 last edited by
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?
-
wrote on 5 Dec 2011, 13:22 last edited by
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]
-
wrote on 5 Dec 2011, 19:42 last edited by
"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 ? -
wrote on 5 Dec 2011, 19:57 last edited by
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.
-
wrote on 5 Dec 2011, 20:06 last edited by
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]
-
wrote on 5 Dec 2011, 20:12 last edited by
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?
-
wrote on 5 Dec 2011, 20:15 last edited by
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] -
wrote on 6 Dec 2011, 19:53 last edited by
hi again
flat property was grate.
:)
thanks to all about help me in this case .
Best regards
5/16