做qt界面的时候这个问题想了一段时间,不过想象也简单,问了别人才知道是那么简单。
有这样一个程序:
#include <QtGui/QApplication>
#include <qtextcodec.h>
#include <QtGui/QDialog>
#include <QtCore/QTimer>
#include "widget.h"
int main(int argc, char *argv[])
{
QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312"));
QApplication a(argc, argv);
QDialog dialog;
dialog.setStyleSheet(QString::fromUtf8("background-image: url(:/images/1.PNG);/n"
"color: rgb(0, 255, 0);/n"
"font: 75 16pt /"/345/256/213/344/275/223/";"));
dialog.setGeometry(QRect(50, 50, 350, 250)); //可设置窗口显示的方位与大小
dialog.setWindowFlags(Qt::FramelessWindowHint); //也是去掉标题栏的语句
Widget w;
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), &w, SLOT(showNormal()));
QObject::connect(&timer, SIGNAL(timeout()), &dialog, SLOT(accept()));
timer.start(5000);
dialog.exec();
w.showNormal(); // 1、可更改的地方。
return a.exec();
}
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
QMessageBox::StandardButton message;
QApplication::setStyle(QStyleFactory::create("plastique"));
QApplication::setPalette(QApplication::style()->standardPalette());
ui.setupUi(this);
connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(mountMessage()));
connect(ui.pushButton_2, SIGNAL(clicked()), this, SLOT(umountMessage()));
connect(ui.pushButton_3, SIGNAL(clicked()), this, SLOT(saveMessage()));
connect(ui.pushButton_5, SIGNAL(clicked()), this, SLOT(adjustMessage()));
connect(ui.pushButton_7, SIGNAL(clicked()), this, SLOT(about_usMessage()));
connect(ui.pushButton_4, SIGNAL(clicked()), this, SLOT(stop_saveMessage()));
connect(ui.pushButton_6, SIGNAL(clicked()), this, SLOT(touchMessage()));
connect(ui.pushButton_8, SIGNAL(clicked()), this, SLOT(exitMessage()));
mount_u(); //挂载U盘成功!
if( !have_video() ) { //if have WebCam?
message = QMessageBox::information(this, tr("摄像头未连接"),
tr("摄像头未连接,请连接摄像头。") );
}
setWindowFlags(Qt::FramelessWindowHint); /2、可更改的地方
setWindowTitle(tr("欢迎使用迷你监控器!"));
}
程序中更改两处显示主窗口的样式。
1、该处可设置窗口大小样式,有四种选择
w.show(); 实际大小
w.showEvent() 自定义大小
w.showFullScreen(); 全屏
w.showMaximized(); 最大化
w.showMinimized(); 最小化
w.showNormal(); 正常
2、该处是去掉窗口标题栏的语句