Problem with QLabel & mouseEvent
hi,
i've got a problem with a QLabel. I want to receive a mousePressEvent only inside the label.
works fine, but
doesn't work and the compiler tells me that imageLabel was not declared. But i declared it with
and put
in the public section of the header.
imageLabel should be able to receive mouseEvents, so am i using mousePressEvent in the wrong way or is there anything else i misunderstood :confused:
Re: Problem with QLabel & mouseEvent
You can only reimplement methods of classes and not objects and "imageLabel" is an object, not a class. You have to subclass QLabel and reimplement the method for the subclass.
Re: Problem with QLabel & mouseEvent
Quote:
Originally Posted by
wysota
You can only reimplement methods of classes and not objects and "imageLabel" is an object, not a class. You have to subclass QLabel and reimplement the method for the subclass.
and how would i do that?
Re: Problem with QLabel & mouseEvent
The same as you did with the main window. Do you know what subclassing (inheritance) means?
Re: Problem with QLabel & mouseEvent
so something like QLabel::imageLabel(){...} would help to make void imageLabel::mousePressEvent(QMouseEvent* event) {...} work?
my knowledge of classes and stuff isn't that good :rolleyes:, so any help in this case is quite useful for me
Re: Problem with QLabel & mouseEvent
Quote:
Originally Posted by
harakiri
so something like QLabel::imageLabel(){...} would help to make void imageLabel::mousePressEvent(QMouseEvent* event) {...} work?
my knowledge of classes and stuff isn't that good :rolleyes:, so any help in this case is quite useful for me
Here is a quick one if this the only part you need.You have to define you own class inheriting QLabel like
Code:
{
Q_OBJECT
public:
protected:
public slots:
};
{
//your code
}
and finally declare MyLabel *label instead of QLabel* label.
Please understand that qt is entirely an object oriented library. If you don't know classes and other OOPS concepts, it becomes very difficult for one to understand what his program is doing. There are lots of c++ books and its better you familarise atleast the basics of c++.