How Can I make Clickable Label in My Project
-
Hi,
It has absolutely nothing to do with your labels. Wherever you'll click on the MainWindow it will show that message.
If you only what to act on a specific QLabel either make that one use the custom class suggested by @mrjj or use an event filter to act only on that QLabel.
wrote on 16 Feb 2020, 13:05 last edited by@SGaist no i will just click on label then message is raised
or any other location i clicked that time message will not raised
-
@Ketan__Patel__0011 said in How Can I make Clickable Label in My Project:
no i will just click on label then message is raised
I would dobut that since you connect the qlabel to a slot which is called on every mouse click as explained in the documentation. Use another slot name.
-
@Ketan__Patel__0011 said in How Can I make Clickable Label in My Project:
no i will just click on label then message is raised
I would dobut that since you connect the qlabel to a slot which is called on every mouse click as explained in the documentation. Use another slot name.
wrote on 16 Feb 2020, 15:07 last edited by -
@Ketan__Patel__0011 said in How Can I make Clickable Label in My Project:
Can you make One Example For Me ?
Of what? creating a member function with a different name than 'mousePressEvent()'? What's the problem?
-
Hi
Several things are wrong
If you are using a plain QLabel, it wont have a clicked signal.
Only using the class in the link it will have it. a plain QLabel cannot be clicked.So lets say you ARE using the new class then this can work.
connect(ui->label,SIGNAL(clicked()),this,SLOT(LabelClicked())); void MainWindow::LabelClicked() { QMessageBox::information(this,"Message","WELCOME"); }
The reason it shows the message anywhere you click currently is due to the fact you added
void MainWindow::mousePressEvent(QMouseEvent *event)
for the MAINWINOW do it will trigger anywhere you click on it.
So its only useful if you where to click anywhere on the whole Mainwindow and not
on any labels. -
Hi
Several things are wrong
If you are using a plain QLabel, it wont have a clicked signal.
Only using the class in the link it will have it. a plain QLabel cannot be clicked.So lets say you ARE using the new class then this can work.
connect(ui->label,SIGNAL(clicked()),this,SLOT(LabelClicked())); void MainWindow::LabelClicked() { QMessageBox::information(this,"Message","WELCOME"); }
The reason it shows the message anywhere you click currently is due to the fact you added
void MainWindow::mousePressEvent(QMouseEvent *event)
for the MAINWINOW do it will trigger anywhere you click on it.
So its only useful if you where to click anywhere on the whole Mainwindow and not
on any labels.wrote on 17 Feb 2020, 05:49 last edited by@mrjj i was write same code in my program but its not worked
-
@mrjj i was write same code in my program but its not worked
Well did you use the ClickableLabel or not ?
-
Well did you use the ClickableLabel or not ?
wrote on 17 Feb 2020, 08:26 last edited by@mrjj please Can you share me a Full code of project ?
like Header file as well as source file code -
@mrjj please Can you share me a Full code of project ?
like Header file as well as source file codeHi
there is no full project.
the wiki page shows what to put in the .cpp and .h.However, if its also due to you not understanding how to use it.
I can make you a test project this evening if that helps? -
@mrjj please Can you share me a Full code of project ?
like Header file as well as source file codewrote on 17 Feb 2020, 10:41 last edited by@Ketan__Patel__0011 Example :
Clickable QLabelthis link will be active for 2 days;
you need to use promote widget after add widget header and class name (**right click options in ui file) -
Hi
there is no full project.
the wiki page shows what to put in the .cpp and .h.However, if its also due to you not understanding how to use it.
I can make you a test project this evening if that helps?wrote on 17 Feb 2020, 13:56 last edited by@mrjj Hello Sir
i am try for last 2 days but nothing is happening
so plz sir help me
How can you share me a test project of clickable_Label ?
-
@Ketan__Patel__0011 Example :
Clickable QLabelthis link will be active for 2 days;
you need to use promote widget after add widget header and class name (**right click options in ui file)wrote on 17 Feb 2020, 14:09 last edited by**@anil_arise hey Brother Thank you So much
It really Good Way My Problem is solved
Again Thank You So Much**
-
@Ketan__Patel__0011 Example :
Clickable QLabelthis link will be active for 2 days;
you need to use promote widget after add widget header and class name (**right click options in ui file)wrote on 2 Mar 2020, 10:34 last edited by@anil_arise Can you share this link again plzzzzz