編輯:關於android開發
2、實現文件
- #ifndef BUILDINDIALOG_H
- #define BUILDINDIALOG_H
- #include
- class buildInDialog : public QDialog
- {
- Q_OBJECT
- public:
- buildInDialog();
- private:
- QPushButton *fileBtn;
- QPushButton *colorBtn;
- QPushButton *fontBtn;
- QPushButton *saveBtn;
- QPushButton *closeBtn;
- QTextEdit *textEdit;
- private slots:
- void fileSlot();
- void colorSlot();
- void fontSlot();
- void saveSlot();
- void closeSlot();
- };
- #endif
3、主函數
- #include "buildInDialog.h"
- buildInDialog::buildInDialog()
- {
- fileBtn = new QPushButton("open");
- colorBtn = new QPushButton("color");
- fontBtn = new QPushButton("font");
- saveBtn = new QPushButton("save");
- closeBtn = new QPushButton("close");
- textEdit = new QTextEdit();
- //布局
- QVBoxLayout *vLay = new QVBoxLayout();
- QHBoxLayout *hLay = new QHBoxLayout();
- vLay->addWidget(fileBtn);
- vLay->addWidget(colorBtn);
- vLay->addWidget(fontBtn);
- vLay->addWidget(saveBtn);
- vLay->addWidget(closeBtn);
- hLay->addWidget(textEdit);
- hLay->addLayout(vLay);
- setLayout(hLay);
- connect(fileBtn, SIGNAL(clicked()), this, SLOT(fileSlot()));
- connect(colorBtn, SIGNAL(clicked()), this, SLOT(colorSlot()));
- connect(fontBtn, SIGNAL(clicked()), this, SLOT(fontSlot()));
- connect(saveBtn, SIGNAL(clicked()), this, SLOT(saveSlot()));
- connect(closeBtn, SIGNAL(clicked()), this, SLOT(closeSlot()));
- }
- void buildInDialog::fileSlot()
- {
- //獲取文件名字
- QString str = QFileDialog::getOpenFileName(this, "打開文件", "/", "All File(*.*)");
- //打開文件
- QFile file(str);
- if(!file.open(QIODevice::ReadWrite))
- return;
- //得到輸入流
- QTextStream in(&file);
- //讀取數據
- while(!in.atEnd())
- {
- QString st = in.readLine();
- textEdit->append(st);
- }
- }
- void buildInDialog::colorSlot()
- {
- //獲取條色板
- QPalette palette = textEdit->palette();
- //打開對話框,獲取顏色
- QColor color = QColorDialog::getColor(palette.color(QPalette::Text), this);
- if(color.isValid())
- {
- //將顏色放到條色板
- palette.setColor(QPalette::Window, color);
- //加載調色板
- textEdit->setPalette(palette);
- }
- }
- void buildInDialog::fontSlot()
- {
- bool ok;
- QFont font = QFontDialog::getFont(&ok);
- if(ok)
- textEdit->setFont(font);
- }
- void buildInDialog::saveSlot()
- {
- bool ok;
- //獲取輸入的信息
- QString str = QInputDialog::getText(this, "輸入對話框", "請輸入名字", QLineEdit::Normal, "wj", &ok);
- //根據輸入的名字打開文件
- QFile file(str);
- file.open(QIODevice::WriteOnly);
- //獲取輸出流
- QTextStream out(&file);
- //將textEdit的內容寫入到out
- out<
toPlainText()<<"\n"; - }
- void buildInDialog::closeSlot()
- {
- QProgressDialog *progress = new QProgressDialog();
- progress->setRange(0, 100);
- for(int i=0; i<=100; i+=10)
- {
- qApp->processEvents();
- progress->setValue(i);
- sleep(1);
- }
- }
- #include "buildInDialog.h"
- #include
- int main(int argc, char *argv[])
- {
- //設置編碼,防止漢字出現亂碼
- QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf-8"));
- QApplication app(argc, argv);
- buildInDialog dialog;
- dialog.show();
- return app.exec();
- }
硅谷社交8--聯系人列表頁面,硅谷社交8--聯系人 1.是否有邀請信息紅點的設置 // 獲取當前是否有新的邀請信息 boolean is_notify = SpUtil
Android基礎入門教程——9.3 使用Camera拍照 Android基礎入門教程——9.3 使用Camera拍照 標簽(空格分隔): A
Android 手機衛士--獲取聯系人信息並顯示與回顯,android回顯前面的文章已經實現相關的布局,本文接著進行相關的功能實現 本文地址:http://www.cnb
界面優化處理技術之(二)編輯文本框組件優化處理,文本框組件開發步驟: 在res下drawable下創建xml文件 添加標簽設置顯示效果 1 <?xml ver