当前位置:   article > 正文

qt中如何去掉主窗口标题栏

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、该处是去掉窗口标题栏的语句

或者这样子

#include "QMouseEvent"

#include "QFileDialog"

public:

QPoint last,pos0;//窗口移动处理

protected:

void mouseMoveEvent(QMouseEvent *);

void mousePressEvent(QMouseEvent *);

//窗口移动处理//

void MainWindow::mouseMoveEvent(QMouseEvent *e)

{

QPoint newpos = e->globalPos();

QPoint upleft = pos0 + newpos - last;

move(upleft);

}

void MainWindow::mousePressEvent(QMouseEvent *e)

{

last = e->globalPos();

pos0 = e->globalPos() - e->pos();

}

//窗口移动处理//

//关闭窗体 和窗体最小化//

void MainWindow::on_pushButton_13_clicked()

{

this->close();

}

void MainWindow::on_pushButton_14_clicked()

{

this->showMinimized();

}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/616562
推荐阅读
相关标签
  

闽ICP备14008679号