Qt 主界面菜单栏和状态栏实现
2012-12-29 14:48
281 查看
因为之前一直用c#来着,最近项目需要跨平台
所以研究Qt发现上手也很快
学习QT学习到后面越发现Qt有些功能很强大
这里展示一个小demo,适合初学者高手绕行。。。
登陆界面
View Code
不做解释,代码基本都有注释!
所以研究Qt发现上手也很快
学习QT学习到后面越发现Qt有些功能很强大
这里展示一个小demo,适合初学者高手绕行。。。
登陆界面
View Code
#include "mainwindow.h" #include "ui_mainwindow.h" #include "QDesktopWidget.h" #include "QTextCodec.h" #include "QMessageBox.h" #include "frmdlg.h" #include "QDateTime.h" #include "QTimer.h" #include "QProgressBar.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); this->resize(800,500); //居中设置 QDesktopWidget* desktop = QApplication::desktop(); int width = desktop->width(); int height = desktop->height(); move((width - this->width())/2, (height - this->height())/2); QTimer *timer = new QTimer(this); //新建定时器 connect(timer,SIGNAL(timeout()),this,SLOT(timerUpDate())); //关联定时器计满信号和相应的槽函数 timer->start(1000); //状态栏初始化 QTextCodec::setCodecForTr( QTextCodec::codecForName("GBK") ); msgLabel=new QLabel(); this->ui->statusBar->addPermanentWidget(msgLabel); ztgLabel=new QLabel(); this->ui->statusBar->addWidget(ztgLabel); QProgressBar *progressBar = new QProgressBar(); progressBar->setTextVisible( false ); progressBar->setRange(0,0); this->ui->statusBar->addWidget(progressBar,1); // QStatusBar的子组件的border设置为0,也就是没有边框 // statusBar()->setStyleSheet(QString("QStatusBar::item{border: 0px}")); } MainWindow::~MainWindow() { delete ui; } void MainWindow::changeEvent(QEvent *e) { QMainWindow::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: ui->retranslateUi(this); break; default: break; } } void MainWindow::on_action_2_activated() { QTextCodec::setCodecForTr( QTextCodec::codecForName("GBK") ); //MessageBox提示框 //QMessageBox::warning(this,tr("警告"),tr("用户名或密码错误!"),QMessageBox::Yes); //打开子窗体 FrmDlg *dlg=new FrmDlg(); dlg->show(); } void MainWindow::timerUpDate() { QTextCodec::setCodecForTr( QTextCodec::codecForName("GBK") ); QDateTime time = QDateTime::currentDateTime(); //获取系统现在的时间 QString str = time.toString("yyyy-MM-dd hh:mm:ss ddd"); //设置显示格式 //设置系统时间显示格式 ui->label->setText(str); //在标签上显示时间 ui->label_2->setText(tr("每秒产生一个随机数:%1").arg(qrand()%10)); ztgLabel->setText(tr("通信状态:%1").arg(qrand()%10)); msgLabel->setText(str); }
不做解释,代码基本都有注释!
相关文章推荐
- Qt 主界面菜单栏和状态栏实现
- Qt 主界面菜单栏和状态栏实现
- Qt实现菜单栏,工具栏,状态栏
- Qt实现菜单栏,工具栏,状态栏
- Qt(三)--- 实现QQ登陆界面头像状态栏的功能
- Qt中实现简单的菜单栏,工具栏和状态栏!
- Qt 界面实现多国语言的切换实例
- Qt-界面动态图的实现
- Qt之界面实现技巧-- 窗体显示,绘制背景,圆角,QSS样式
- Qt 国际化之二:多国语界面动态切换的实现
- Qt之界面实现技巧
- Qt实现简单的TCP网络电子词典(带界面,能并发)
- QT下 TableWidget 实现右键菜单栏,以及TableWidget整体美化工作。
- QT实现简单的抽奖界面
- Qt 之QToolButton 实现QQ界面按钮效果
- Qt学习之八:菜单栏、工具栏和状态栏
- Qt之实现网络下发配置的半透明友好提示界面
- Qt之自定义界面(实现无边框、可移动)
- Qt实现打开QQ聊天界面(售后服务)
- Qt与HTML,jQuery交互实现类似QQ聊天界面