Hi,
I am using QT 4.2.2. I have a label in my main window. I want a "QLabel::clicked()" signal for my label, ie, i want to call a function when i click on a lable. How can I do that.
Hi,
I am using QT 4.2.2. I have a label in my main window. I want a "QLabel::clicked()" signal for my label, ie, i want to call a function when i click on a lable. How can I do that.
Hi,
Not clear!!!!!!!!!!!
Qt Code:
{ connect( this, SIGNAL( clicked() ), this, SLOT( slotClicked() ) ); } { emit clicked(); } void myLabel::slotClicked() { qDebug()<<"Clicked"; }To copy to clipboard, switch view to plain text mode
Hi,
When I give this code, qt display some errors. Can you give me a small discreption aout this code. because, i am a new comer in QT!!!!!
How do you "give" the code?When I give this code, qt display some errors.
That is a QLabel subclass.
You have to define your own class, and add those methods to it and also the signal.
That code is no not complete. It is just a suggestion.
You will have to embed it in your application.
Regards
Ok, here is the full code
//.h
Qt Code:
{ Q_OBJECT public: ~myLabel(){} signals: void clicked(); public slots: void slotClicked(); protected: }; #endifTo copy to clipboard, switch view to plain text mode
.cppQt Code:
{ connect( this, SIGNAL( clicked() ), this, SLOT( slotClicked() ) ); } void myLabel::slotClicked() { qDebug()<<"Clicked"; } { emit clicked(); }To copy to clipboard, switch view to plain text mode
In your mainWindows.cpp in the constructor add this
Qt Code:
{ myLabel* m_label = new myLabel(this); }To copy to clipboard, switch view to plain text mode
I have not tested the code so please correct the code if you get any errors
Thanks
Hi there!!
And how is it possible for the Widget to catch the clicked signal from the label???
Thanks for the help!!!
Best regards!
code of vermarajeev works well for me![]()
If you use this example you can catch it like this:MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent)
{
myLabel* m_label = new myLabel(this);
}
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent)
{
myLabel* m_label = new myLabel(this);
connect(myLabel, SIGNAL(clicked()), SLOT(myActionWhenMyLabelHasBeenClicked()));
}
Jake123 (27th January 2013)
Hi,
only one remark:
The "real click" will be better simulated if you will use the
mouseReleaseEvent(QMouseEvent *e) instead of mousePressEvent(QMouseEvent *e)
regards
me![]()
Last edited by lotek; 11th October 2010 at 10:35.
Jake123 (27th January 2013)
I agree with Lotek.
A mouse "click" is traditionally a full press-then-release event series.
Interpreting a click on a mouse press disallows the user from canceling the click when they drag the mouse away from the item, amongst other things.
Just my two-cents.
doggy
Bookmarks