This is the code I wrote. I got errors in Widget.cpp file - what do i do about those?
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QLabel>
#include <QWidget>
namespace Ui {
class Widget;
}
{
Q_OBJECT
public:
explicit Widget
(QWidget *parent
= 0);
~Widget();
private:
Ui::Widget *ui;
};
{
Q_OBJECT
public:
~Label();
public slots:
void mouseOverLabel();
void mouseNotOverLabel();
protected:
virtual void enterEvent
(QEvent *);
virtual void leaveEvent
(QEvent *);
signals:
};
#endif // WIDGET_H
#ifndef WIDGET_H
#define WIDGET_H
#include <QLabel>
#include <QWidget>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private:
Ui::Widget *ui;
};
class Label : public QLabel
{
Q_OBJECT
public:
Label(QWidget *parent=NULL);
~Label();
public slots:
void mouseOverLabel();
void mouseNotOverLabel();
protected:
virtual void enterEvent(QEvent *);
virtual void leaveEvent(QEvent *);
signals:
void enter(QString);
void leave(QString);
};
#endif // WIDGET_H
To copy to clipboard, switch view to plain text mode
widget.cpp
#include "widget.h"
#include "ui_widget.h"
ui(new Ui::Widget)
{
ui->setupUi(this);
setFixedSize(145,45);
Label *label = new Label;
label->setGeometry(10,10,100,30);
label->setText("Where is the Mouse?");
connect(label,
SIGNAL(enter
(QString)),label,
SLOT(mouseOverLabel
()));
connect(label,
SIGNAL(leave
(QString)),label,
SLOT(mouseNotOverLabel
()));
}
void Label::mouseOverLabel()
{
label->setText("The Mouse is Over Me :-) ");
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
setFixedSize(145,45);
Label *label = new Label;
label->setGeometry(10,10,100,30);
label->setText("Where is the Mouse?");
connect(label,SIGNAL(enter(QString)),label,SLOT(mouseOverLabel()));
connect(label,SIGNAL(leave(QString)),label,SLOT(mouseNotOverLabel()));
}
void Label::mouseOverLabel()
{
label->setText("The Mouse is Over Me :-) ");
To copy to clipboard, switch view to plain text mode
ERROR: Label was not declared in this scope
}
void Label::mouseNotOverLabel()
{
label->setText("Where is the Mouse?");
}
void Label::mouseNotOverLabel()
{
label->setText("Where is the Mouse?");
To copy to clipboard, switch view to plain text mode
ERROR: Label was not declared in this scope
}
void Label
::enterEvent(QEvent *e
)[B
][COLOR
="red"]ERROR
:unused paramter e
[/COLOR
][/B
] {
emit enter( text() );
}
void Label
::leaveEvent(QEvent *e
) {
emit leave( text() );
}
Widget::~Widget()
{
delete ui;
}
}
void Label::enterEvent(QEvent *e)[B][COLOR="red"]ERROR:unused paramter e[/COLOR][/B]
{
emit enter( text() );
}
void Label::leaveEvent(QEvent *e)
{
emit leave( text() );
}
Widget::~Widget()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
Bookmarks