3
오른쪽 클릭과 왼쪽 클릭을 구별해야하므로 mouseClickEvent
을 다시 구현하려고했습니다. 을 WavList
로 승격하고 다음 코드를 작성했지만 오류가 발생했습니다.Qt 위젯 프로모션 :이 두 코드의 차이점은 무엇입니까?
wavlist.h
#ifndef WAVLIST_H
#define WAVLIST_H
#include <QWidget>
#include <QListView>
#include <QMouseEvent>
#include <QDebug>
class WavList : public QListView
{
Q_OBJECT
public:
explicit WavList(QWidget *parent = 0);
protected:
void mousePressEvent(QMouseEvent* event);
};
#endif // WAVLIST_H
wavlist.cpp
#include "wavlist.h"
WavList::WavList(QWidget *parent) : QWidget(parent)
{
qDebug() << "lol";
}
void WavList::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton)
{
event->ignore();
}
else
{
QListView::mousePressEvent(event);
}
}
나는 다음과 같은 오류 있어요 : C2614: 'WavList': illegal member initialization: 'QWidget' is not a base or member
합니다.
그래서이 코드를 수정했습니다.
WavList::WavList(QWidget *parent)
{
this->setParent(parent);
qDebug() << "lol";
}
그리고이 방법이 효과적이었습니다. 제 질문은, 차이점은 무엇입니까?
답변 해 주셔서 감사합니다. – Azruine