问题描述
我有一个继承自QWidget的MediaPanel,并且我想隐藏标题栏,但是如果我使用 setWindowFlags(Qt :: CustomizeWindowHint | Qt :: WindowTitleHint); c $ c>(或其他类似的标记),结果仍然相同:
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 :
,如果我使用 setWindowFlags(Qt :: Window | Qt :: FramelessWindowHint);
我会丢失所有按钮,标签和滑块:
and if I use setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
I lose all the buttons, labels and sliders :
我玩过Qt示例和某种组合似乎是不可能的...
I've played with the Qt example and some combination seems to be impossible...
代码的一部分,有人可以告诉我应该在哪里设置标志吗?
I've posted a reduced part of my code, could someone tell me where should I set the flags ?
#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
JokerWindow.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
JokerWindow.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;
}
推荐答案
setWindowFlags(Qt :: Window | Qt :: FramelessWindowHint)为我工作。确保在最高级别的窗口上应用设置。例如在main.cpp中,请参见下图,原谅有线3D物体,测试一些OpenGL代码。
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.
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
WoodPuppet window;
window.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
window.show();
}
这篇关于Qt删除标题栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!