1,显示效果
2,页面编辑方式,画好页面之后转到槽函数
3,各个槽函数代码简单实现
3.1,打开
1 void Filewin::on_actionopen_triggered() 2 { 3 QString fitler=QString("Text from(*.cpp *.h)"); 4 filename=QFileDialog::getOpenFileName(this,"choose file","./",fitler); 5 ui->statusBar->showMessage(filename); 6 7 QFile file(filename); 8 file.open(QIODevice::ReadOnly); 9 QString str=file.readAll(); 10 ui->textEdit->setText(str); 11 file.close(); 12 }
3.2,保存
1 void Filewin::on_actionsave_triggered() 2 { 3 QFile file(filename); 4 file.open(QIODevice::WriteOnly); 5 QString msg=ui->textEdit->toPlainText(); 6 file.write(msg.toUtf8()); 7 file.close(); 8 }
3.3,另存为
1 void Filewin::on_actionssave_triggered() 2 { 3 QString filepath=QFileDialog::getSaveFileName(this,"save as","./","Text (*.c *.cpp)"); 4 QFile file(filepath); 5 file.open(QIODevice::WriteOnly); 6 QString msg=ui->textEdit->toPlainText(); 7 file.write(msg.toUtf8()); 8 file.close(); 9 }
3.4,设置字体
1 void Filewin::on_actionfont_triggered() 2 { 3 bool ok; 4 QFont font=QFontDialog::getFont(&ok,this); 5 if(ok) 6 { 7 this->ui->textEdit->setFont(font); 8 } 9 }
3.5 退出
1 void Filewin::on_actionquit_triggered() 2 { 3 this->close(); 4 }