Qt删除标题栏

时间:2013-11-29 17:17:46

标签: c++ qt window

我有一个继承自QWidget的MediaPanel,我想隐藏标题栏但是如果我用setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);(或其他一些标志)设置标志,则结果仍然相同:{{0 }}

如果我使用setWindowFlags(Qt::Window | Qt::FramelessWindowHint);,我会丢失所有按钮,标签和滑块:mediaPanel

我玩过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;
}

1 个答案:

答案 0 :(得分:30)

setWindowFlags(Qt :: Window | Qt :: FramelessWindowHint)适合我。确保在最高级别窗口中应用该设置。例如在main.cpp中看到下图,原谅有线3D的东西,测试一些OpenGL代码。 enter image description here

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  WoodPuppet window;

  window.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
  window.show();
}