how to click the qlabel to perform some action....
-
- list item
-
Hi! See this wiki article: Clickable QLabel.
-
Hi! See this wiki article: Clickable QLabel.
Another solution could be using event filter
//MyClass.h QLabel *clickablelabel //MyClass.cpp MyClass::MyClass(QObject *parent) { //... clickablelabel = new QLabel("Click Me!"); clickablelabel->installEventFilter(this); //... } bool MyClass::eventFilter(QObject *o, QEvent *e) { if(o == clickablelabel && e->type() == QMouseEvent::MouseButtonPress) { //do something } /* //using metaObject() thingies if(e->type() == QMouseEvent::MouseButtonPress && o->metaObject()->className() == (new QLabel)->metaObject()->className()) { //do something } */ return QObject::eventFilter(o,e); }
-
Two other options:
If it's clickable why not use a button? You can make it flat if you don't want the usual button bevel.
You can put an html link in the label and it will emit a
linkActivated
signal when you click on it. -
so 3 super answers to the cool description:
list item
:)
-
Hi! See this wiki article: Clickable QLabel.
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QLabel *dispimg= new QLabel(this);
dispimg->setStyleSheet("image:url(E:/may/may_7/images/singdisp.png);");
dispimg->setGeometry(330,190,200,200);
connect(this, SIGNAL( clicked() ), this, SLOT( slotClicked() ) );}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::mousePressEvent ( QMouseEvent * event )
{
emit clicked();
}void MainWindow::slotClicked()
{
qDebug()<<"hello";
}above code is what i used...
-
it work's all area of the mouse pressed....i want to click the particular label
-
Please read the answers above, there is even code you can use.
-
Hi! See this wiki article: Clickable QLabel.
@Wieland i want to click for the particular label....
-
can any one send the coding ..for above question
-
thanks for all..i got it....
-
This post is deleted!