두 가지 클래스가 있습니다.
typedef std::shared_ptr<AdaptedWidget> window_ptr;
class WindowManager
{
public:
...
private:
std::stack<window_ptr> m_windowsStack;
}
과
class AdaptedWidget: public QWidget
{
Q_OBJECT
public:
AdaptedWidget(AdaptedWidget *parent = 0);
bool event(QEvent *event);
};
bool AdaptedWidget::event(QEvent *event)
{
if (event->type() == QEvent::NonClientAreaMouseButtonPress ||
event->type() == QEvent::MouseButtonPress)
{
qDebug() << "mainwindwo press";
}
return QWidget::event(event);
}
AdaptedWidget
내 WindowManager
개체 에서 개체에서 발생하는 이벤트에 대한 정보를 가져와야 합니다. 어떻게해야합니까?
이벤트 필터 는 작업을 수행하는 Qt 방법입니다.
귀하의 확인 WindowManager
클래스의 서브 클래스 QObject
와의 구현 제공 eventFilter()
방법.
그 후에는 인스턴스를 이벤트 필터로 설치 하는 AdaptedWidget
용도 installEventFilter()
를 만들 때마다 WindowManager
.
class WindowManager : public QObject
{
public:
...
bool eventFilter(QObject* obj, QEvent* ev);
private:
std::stack<window_ptr> m_windowsStack;
}
과
bool WindowManager::eventFilter(QObject* obj, QEvent* ev){
AdaptedWidget* widget= qobject_cast<AdaptedWidget*>(obj);
if(ev->type == /*type of event you are interested in*/){
//you can compare widget against the stack of widgets you have
//if you want to stop widget from receiving the event you can return true
}
return false;
}
각 AdaptedWidget
인스턴스를 만들 때 WindowManager
이벤트 필터로 설치합니다 .
AdaptedWidget* widget= new AdaptedWidget;
widget->installEventFilter(/*your WindowManager instance*/);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다