简体   繁体   English

Qt 移除标题栏

[英]Qt remove title bar

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);我有一个继承自 QWidget 的 MediaPanel,我想隐藏标题栏,但是如果我使用setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint); (or some other flags like ) the result is still the same: (或其他一些标志,如)结果仍然相同:媒体面板

and if I use setWindowFlags(Qt::Window | Qt::FramelessWindowHint);如果我使用setWindowFlags(Qt::Window | Qt::FramelessWindowHint); I lose all the buttons, labels and sliders:我丢失了所有按钮、标签和滑块:空媒体面板

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;
}

setWindowFlags(Qt::Window | Qt::FramelessWindowHint) works for me. setWindowFlags(Qt :: Window | Qt :: FramelessWindowHint)适合我。 Make sure you are applying the setting on your highest level window. 确保在最高级别窗口中应用该设置。 eg in the main.cpp See the image below, forgive the wired 3D thing, testing some OpenGL code. 例如在main.cpp中看到下图,原谅有线3D的东西,测试一些OpenGL代码。 在此输入图像描述

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

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

This is what I did with qPysie6.这就是我对 qPysie6 所做的。 I just directly use flags property in QML.我只是直接在 QML 中使用 flags 属性。

import QtQuick 2.15
import QtQuick.Controls 2.15
ApplicationWindow {
    id: root
    visible: true
    width: 400; height: 300
    title: "Windows"
    flags: Qt.FramelessWindowHint
}

QWindow Class QWindow Class

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM