0

I am creating an interface using Qt. I added a button and when it comes up with the mouse I see the QLabel and ask for information.(Button will not be clicked) How can I do it.

I wrote following code. But, not view ui->checkout button. I want to view CheckoutButton.

mainwindow.h

public:
  explicit PRJSVN(QWidget *parent=0);
  ~PRJSVN();

   bool eventFilter(QObject *obj, QEvent *e);

mainwindow.cpp

PRJSVN::PRJSVN(QWidget *parent):
QMainWindow(parent),
ui(new Uİ::PRJSVN)
{
    ui->setupUi(this);
    ui->CheckoutButton->installEventFilter(this);
}

bool PRJSVN::eventFilter(QObject *obj, QEvent *e)
{
    if(obj==(QObject*)ui->CheckoutButton)
    {
        if(e->type()==QEvent::Enter)
        {
            ui->label->SetText("Checkout Button");
        }
    }
    return QWidget::eventFilter(obj,e);
}
oğuzhan kaynar
  • 77
  • 1
  • 10

2 Answers2

1

There are at least 2 ways to do perform an action on button mouseover. See this question:

The first way is by subclassing the push button and add/emit a new hover signal on the enter event.

The second way is using the event filters, in the widget with the button. When using the event filter approach in the linked question, you should change the event filter function to:

bool YourWidget::eventFilter(QObject *obj, QEvent *e)
{
    if (obj == (QObject*)yourPushButton) {
        if (e->type() == QEvent::Enter)
        {
            // some action on mouseover
        }
    }
    return QWidget::eventFilter(obj, e);
}

and use the event filter by:

yourPushButton->installEventFilter(this);
Community
  • 1
  • 1
Tom Conijn
  • 291
  • 2
  • 8
0

Error: 'CheckoutButton' was not declared in this scope

Because your class doesn't have a member called CheckoutButton, you class has a member called ui and that object has a member called CheckoutButton.

See your constructor on how to access it.

Kevin Krammer
  • 5,159
  • 2
  • 9
  • 22