我有一个继承自QWidget的MediaPanel,我想隐藏标题栏,但是如果我用setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
设置标志(或其他类似标志),结果仍然是相同的:
如果我使用setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
,则会丢失所有按钮,标签和滑块:
我玩过Qt示例,似乎无法实现某种组合...
编辑:
我发布了代码的简化部分,有人可以告诉我在哪里设置标志吗?
main.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
#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
#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
#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
#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代码。
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
WoodPuppet window;
window.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
window.show();
}
关于c++ - Qt删除标题栏,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20290688/