2023-08-09 18:22:00 +08:00
|
|
|
#include "form8.h"
|
|
|
|
#include "ui_form8.h"
|
|
|
|
|
|
|
|
Form8::Form8(QWidget *parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
ui(new Ui::Form8)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
ui->Form8label->setWordWrap(true);
|
|
|
|
// ui->Form8label->setMinimumWidth(400);
|
|
|
|
// ui->Form8label->setMaximumWidth(400);
|
|
|
|
}
|
|
|
|
|
|
|
|
Form8::~Form8()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Form8::event(QEvent *evt)
|
|
|
|
{
|
|
|
|
qDebug()<<"事件分发"<<evt->type();
|
2023-08-10 12:05:02 +08:00
|
|
|
if(evt->type() == QEvent::KeyRelease){
|
2023-08-09 18:22:00 +08:00
|
|
|
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(evt);
|
2023-08-10 12:05:02 +08:00
|
|
|
if(keyEvent->key() == Qt::Key_Tab||keyEvent->key() == Qt::Key_O){
|
2023-08-09 18:22:00 +08:00
|
|
|
// ui->Form8label->setText(tr("按下 %1 键").arg(keyEvent->text()));
|
|
|
|
qDebug()<<tr("按下 %1 键").arg(keyEvent->text());
|
2023-08-10 12:05:02 +08:00
|
|
|
return true;
|
2023-08-09 18:22:00 +08:00
|
|
|
}
|
|
|
|
// return false; // 不分发此事件
|
|
|
|
}
|
2023-08-10 12:05:02 +08:00
|
|
|
// return QWidget::event(evt);
|
|
|
|
return false;
|
2023-08-09 18:22:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Form8::keyPressEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
QString s = ui->Form8label->text();
|
|
|
|
// 如果按下的是换行
|
|
|
|
if(event->key() == Qt::Key_Enter){
|
|
|
|
s+="\r\n";
|
|
|
|
}else if(event->key() == Qt::Key_Space){
|
|
|
|
s.clear();
|
|
|
|
}else if(event->key() == Qt::Key_Backspace){
|
|
|
|
// s.remove(s.size()-1,1);
|
|
|
|
s.chop(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
s += event->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->Form8label->setText(s);
|
|
|
|
}
|
|
|
|
|