Constructor:
in mainwindow.h
...
private:
myLabel *l;
.....
...
private:
myLabel *l;
.....
To copy to clipboard, switch view to plain text mode
in mainwindow.cpp
...
l = new myLabel();
l->setAutoFillBackground(true);
image
= new QImage(s
);
//Muss im debug-Ordner sein!!!l
->setPixmap
(QPixmap::fromImage(*image
));
l->setMaximumHeight(image->height());
l->setMaximumWidth(image->width());
l->setInfo(i+1);
...
...
QString s = "l"+QString::number(i+1)+".png";
l = new myLabel();
l->setBackgroundRole(QPalette::Dark);
l->setAutoFillBackground(true);
image = new QImage(s);//Muss im debug-Ordner sein!!!
l->setPixmap(QPixmap::fromImage(*image));
l->setMaximumHeight(image->height());
l->setMaximumWidth(image->width());
l->setInfo(i+1);
...
To copy to clipboard, switch view to plain text mode
--------------------------------------------------------------------
myLabel.h
#ifndef MYLABEL_H
#define MYLABEL_H
{
Q_OBJECT
public:
~myLabel(){}
void setInfo(int i);
int getInfo();
private:
int zahl;
signals:
void clicked();
public slots:
void slotClicked();
protected:
};
#endif
#ifndef MYLABEL_H
#define MYLABEL_H
class myLabel : public QLabel
{
Q_OBJECT
public:
myLabel( const QString & text, QWidget * parent = 0 );
~myLabel(){}
void setInfo(int i);
int getInfo();
private:
int zahl;
signals:
void clicked();
public slots:
void slotClicked();
protected:
void mousePressEvent ( QMouseEvent * event ) ;
};
#endif
To copy to clipboard, switch view to plain text mode
myLabel.cpp
#include "mylabel.h"
{
connect( this, SIGNAL( clicked() ), this, SLOT( slotClicked() ) );
}
void myLabel::slotClicked()
{
qDebug()<<"Clicked";
}
{
emit clicked();
}
void myLabel::setInfo(int i)
{
zahl=i;
}
int myLabel::getInfo()
{
return zahl;
}
#include "mylabel.h"
myLabel::myLabel( const QString & text, QWidget * parent = 0 )
:QLabel(parent)
{
connect( this, SIGNAL( clicked() ), this, SLOT( slotClicked() ) );
}
void myLabel::slotClicked()
{
qDebug()<<"Clicked";
}
void myLabel::mousePressEvent ( QMouseEvent * event )
{
emit clicked();
}
void myLabel::setInfo(int i)
{
zahl=i;
}
int myLabel::getInfo()
{
return zahl;
}
To copy to clipboard, switch view to plain text mode
The Error is:
no matching function for call to 'myLabel::myLabel()'
candidates are: myLabel::myLabel(const QString&,QWidget*)
note: myLabel::myLabel(const myLabel&)
Bookmarks