I would like to catch the Space key in my app.
The header:
#pragma once
#include <QWidget>
#include <iitem.hpp>
#include <ui_invpg.h>
{
Q_OBJECT
public :
InvPage();
virtual ~InvPage();
void clear();
void ClearSel();
void MakeList();
void MakeInv();
void LoadData();
IItem *theitem;
bool addit;
protected :
virtual void keyPressEvent
( QKeyEvent *event
);
private :
Ui::InvPage ui;
private slots :
};
#pragma once
#include <QWidget>
#include <iitem.hpp>
#include <ui_invpg.h>
class InvPage : public QWidget
{
Q_OBJECT
public :
InvPage();
virtual ~InvPage();
void clear();
void ClearSel();
void MakeList();
void MakeInv();
void LoadData();
IItem *theitem;
bool addit;
protected :
virtual void keyPressEvent( QKeyEvent *event );
private :
Ui::InvPage ui;
private slots :
void ItemClicked( QListWidgetItem *item );
};
To copy to clipboard, switch view to plain text mode
The ctor contains only ui.setupUi(this). The (current) implementation should test whether the handler works:
#include <QWidget>
#include <QKeyEvent>
#include <myapp.hpp>
#include <myframe.hpp>
#include <invpage.hpp>
#include <iitem.hpp>
#include <data.hpp>
void InvPage
::keyPressEvent( QKeyEvent *event
) {
if( event->key() == Qt::Key_Space )
{
char str[40];
sprintf(str,"%s",(addit ? "addit = true" : "addit = false"));
TheApp->frame->statusBar()->showMessage(str,2000);
}
}
#include <QWidget>
#include <QKeyEvent>
#include <myapp.hpp>
#include <myframe.hpp>
#include <invpage.hpp>
#include <iitem.hpp>
#include <data.hpp>
void InvPage::keyPressEvent( QKeyEvent *event )
{
if( event->key() == Qt::Key_Space )
{
char str[40];
sprintf(str,"%s",(addit ? "addit = true" : "addit = false"));
TheApp->frame->statusBar()->showMessage(str,2000);
}
QWidget::keyPressEvent(event);
}
To copy to clipboard, switch view to plain text mode
It does not work. Putting a breakpoint at the "if" shows that the handler isn't called at all. What kind of blunder am I making? (Note: the statusbar works fine.)
Bookmarks