mercredi 5 octobre 2016

Subclassing QLabel and use it in QWidget class

Vote count: 0

When i try to put QLabel in QWidget class its not work properly (no hover event or click event only the label pixmap is show) only the last instance work properly,

this is QLabel subclass header:

#include <QObject>
#include <QLabel>
class myLabel : public QLabel
{
    Q_OBJECT
public:
    myLabel();

protected:
    void mousePressEvent(QMouseEvent *);
    void enterEvent(QEvent *);
    void leaveEvent(QEvent *);


signals :
    void labelClicked();
    void enterSignal();
    void leaveEventSignal();

private:

};

this class to make a labelButton:

#include <QObject>
#include <QWidget> 
#include "mylabel.h"
class labelButton : public QWidget
{
    Q_OBJECT
public:
    labelButton();

    //some functions

private slots:
    //slots

private:
   //private member
};

and this the class that i want to use the labelButtons in:

#include <QWidget> 
#include "labelbutton.h"

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

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

private:
    Ui::Widget *ui;

    labelButton *b_1, *b_2;

};

here is widget.cpp:

   Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    b_1 = new labelButton;
    b_1->setParent(this);
    b_1->moveButton(70, 100);
    //some functions to initialize the labelButton
    b_1->show();

    //-----------------------

    b_2 = new labelButton;
    b_2->setParent(this);
    b_2->moveButton(70, 200);
    //some functions to initialize the labelButton
    b_2->show();

    //-----------------------

    labelButton *b_3 = new labelButton;
    b_3->setParent(this);
    b_3->moveButton(70, 300);
    //some functions to initialize the labelButton
    b_3->show();
}

asked 15 secs ago

Let's block ads! (Why?)



Subclassing QLabel and use it in QWidget class

Aucun commentaire:

Enregistrer un commentaire