保存
void Widget::on_savebtn_clicked()
{
QString filename = QFileDialog::getSaveFileName(this, "保存", "C:/Users/yc/Desktop/", "图片 (*.png *.xpm *.jpg);;文本 (*.txt);;所有文件 (*.*)");
if(filename.isNull()){
QMessageBox::information(this, "提示", "取消保存");
return ;
}
QFile file(filename);
if(!file.open(QFile::ReadWrite)){
return ;
}
QString msg = ui->textEdit->toPlainText();
file.write(msg.toLatin1());
file.close();
}
移动
//键盘按下事件的处理函数的定义
void Widget::keyPressEvent(QKeyEvent *event)
{
//qDebug() << "键盘按下" << event->text() << "键值为" << event -> key();
switch(event->key()){
case 'W':if(ui->label->y() <= 0-ui->label->height()){
ui->label->move(ui->label->x(), this->height());
}
ui -> label -> move(ui->label->x(), ui->label->y()-1);break;
case 'S':if(ui->label->y() >= this->height()){
ui->label->move(ui->label->x(), 0-ui->label->height());
}
ui -> label -> move(ui->label->x(), ui->label->y()+1);break;
case 'A':if(ui->label->x() <= 0-ui->label->width()){
ui->label->move(this->width(), ui->label->height());
}
ui -> label -> move(ui->label->x()-1, ui->label->y());break;
case 'D':if(ui->label->x() >= this->width()){
ui->label->move(0-ui->label->width(), ui->label->y());
}
ui -> label -> move(ui->label->x()+1, ui->label->y());break;
}
}