Qt程序主界面
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTextCodec *codec = QTextCodec::codecForName("GB2312");
QTextCodec::setCodecForTr(codec);
QTextCodec::setCodecForLocale(codec);
QTextCodec::setCodecForCStrings(codec);
SysDialog *win = new SysDialog();
win->show();//显示主界面
return app.exec();
}
界面代码分析
主界面背景实现代码
SysDialog::SysDialog( QWidget *parent): QDialog( parent)
{
...
this->setMinimumSize(800,480);
this->setMaximumSize(800,480);
this->setWindowIcon(QPixmap( ":/images/1.png") );
this->setWindowTitle(tr("GP9001车载GPS监控系统"));
label_pic_bg = new QLabel(this);
label_pic_bg->setGeometry(QRect(0, 0, 800, 480));
label_pic_bg->setPixmap(QPixmap(":/images/gp9001bg.jpg"));
label_pic_bg->setScaledContents(true);
子功能按钮实现
toolButtonState = new QToolButton(this);
toolButtonState->setGeometry(QRect(20, 320, 100, 100));
toolButtonState->setText( tr( "系统状态" ) );
toolButtonState->setIcon( QPixmap( ":/images/car.png") );
toolButtonState->setIconSize( QPixmap( ":/images/car.png").size() );
toolButtonState->setAutoRaise( TRUE );
toolButtonState->setToolButtonStyle( Qt::ToolButtonTextUnderIcon);
connect(toolButtonState,SIGNAL(clicked()),this,SLOT(goCmdState()));
对应的槽函数
void SysDialog::goCmdState()
{
ShowDialog *myDlg = new ShowDialog(this);
if(myDlg->exec()){
qDebug() << 1;
}else{
qDebug() << 2;
}
delete myDlg;
}
1.控件采用绝对坐标进行布局
label_pic_bg->setGeometry(QRect(30, 80, 800, 480));
//x=30,y=80,width=800,height=480
2.dialog背景如何设置为图片
label_pic_bg = new QLabel(this);
label_pic_bg->setGeometry(QRect(0, 0, 800, 480));
label_pic_bg->setPixmap(QPixmap(":/images/9bg.jpg"));
label_pic_bg->setScaledContents(true);
3.窗口之间如何进行调用
例如在窗口A中通过单击按钮启动窗口B
a)调用者A
调用A设置slot,new一个B窗口,使用exec()方法启动B窗口。
connect(toolButtonState,SIGNAL(clicked()),this,SLOT(goCmdState()));
void SysDialog::goCmdState()
{
SetDialog *loginDlg = new SetDialog(this);
if(loginDlg->exec()){
qDebug() << 1;
}else{
qDebug() << 2;
}
delete loginDlg;
}
b)被调用者B
调用窗口按钮单击后能关闭窗口
connect(toolButton,SIGNAL(clicked()),this,SLOT(accept()));
Copyright © 2016 www.91arm.com 【91创客学堂】