C++ Qt删除标题栏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20290688/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Qt remove title bar
提问by Thomas Ayoub
I've a MediaPanel which inherits from QWidget and I want to hide the title bar but event if I set the flags with setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
(or some other flags like ) the result is still the same :
我有一个继承自 QWidget 的 MediaPanel,我想隐藏标题栏,但如果我设置了标志setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
(或其他一些标志,如),结果仍然相同:
and if I use setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
I lose all the buttons, labels and sliders :
如果我使用,setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
我会丢失所有按钮、标签和滑块:
I've played with the Qt example and some combination seems to be impossible...
我玩过 Qt 的例子,有些组合似乎是不可能的......
EDIT :
编辑 :
I've posted a reduced part of my code, could someone tell me where should I set the flags ?
我已经发布了我的代码的减少部分,有人可以告诉我应该在哪里设置标志吗?
main.cpp :
主.cpp :
#include <QApplication>
#include "JokerWindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
JokerWindow w(&settings);
w.show();
return a.exec();
}
JokerWindow.h
小丑窗口.h
#ifndef JOKERWINDOW_H
#define JOKERWINDOW_H
#include <QMainWindow>
#include "PhCommonUI/PhMediaPanelDialog.h"
namespace Ui {
class JokerWindow;
}
class JokerWindow : public QMainWindow
{
Q_OBJECT
public:
explicit JokerWindow(QSettings *settings);
~JokerWindow();
private:
PhMediaPanelDialog _mediaPanel;
};
#endif // MAINWINDOW_H
JokerWindow.cpp
小丑窗口.cpp
#include "JokerWindow.h"
#include "ui_JokerWindow.h"
JokerWindow::JokerWindow(QSettings *settings) :
QMainWindow(NULL),
ui(new Ui::JokerWindow)
{
_mediaPanel.show();
}
JokerWindow::~JokerWindow()
{
delete ui;
}
PhMediaPanel.h
PhMediaPanel.h
#ifndef PHMEDIAPANEL_H
#define PHMEDIAPANEL_H
#include <QWidget>
namespace Ui {
class PhMediaPanel;
}
class PhMediaPanel : public QWidget
{
Q_OBJECT
public:
explicit PhMediaPanel(QWidget *parent = 0);
~PhMediaPanel();
private:
Ui::PhMediaPanel *ui;
};
#endif // PHMEDIAPANEL_H
PhMediaPanel.cpp
PhMediaPanel.cpp
#include "PhMediaPanel.h"
#include "ui_PhMediaPanel.h"
PhMediaPanel::PhMediaPanel(QWidget *parent) :
QWidget(parent)
{
ui->setupUi(this);
}
PhMediaPanel::~PhMediaPanel()
{
delete ui;
}
回答by sirian_ye
setWindowFlags(Qt::Window | Qt::FramelessWindowHint) works for me. Make sure you are applying the setting on your highest level window. e.g in the main.cpp See the image below, forgive the wired 3D thing, testing some OpenGL code.
setWindowFlags(Qt::Window | Qt::FramelessWindowHint) 对我有用。确保您在最高级别的窗口上应用设置。例如在 main.cpp 看下图,原谅有线 3D 的东西,测试一些 OpenGL 代码。
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
WoodPuppet window;
window.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
window.show();
}