A way:
MainWindow
::MainWindow(QWidget *parent
){
l->installEventFilter( this );
}
{
if( event
->type
() == QEvent::MouseButtonRelease ) {
qDebug() << "Label action!"; // do what you want here
}
}
MainWindow::MainWindow(QWidget *parent)
{
QLabel* l = new QLabel( "test", this );
l->installEventFilter( this );
}
bool MainWindow::eventFilter( QObject* object, QEvent* event )
{
if( event->type() == QEvent::MouseButtonRelease )
{
qDebug() << "Label action!"; // do what you want here
}
return QMainWindow::eventFilter( object, event );
}
To copy to clipboard, switch view to plain text mode
A better way:
MainWindow
::MainWindow(QWidget *parent
){
connect( button, SIGNAL( clicked() ), this, SLOT( buttonClicked() ) );
}
void MainWindow::buttonClicked( void )
{
qDebug() << "Action!"; // do what you want here
}
MainWindow::MainWindow(QWidget *parent)
{
QPushButton* button = new QPushButton( "test", this );
connect( button, SIGNAL( clicked() ), this, SLOT( buttonClicked() ) );
}
void MainWindow::buttonClicked( void )
{
qDebug() << "Action!"; // do what you want here
}
To copy to clipboard, switch view to plain text mode
Bookmarks