21

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 : mediaPanel

and if I use setWindowFlags(Qt::Window | Qt::FramelessWindowHint); I lose all the buttons, labels and sliders : empty media panel

I've played with the Qt example and some combination seems to be impossible...

EDIT :

I've posted a reduced part of my code, could someone tell me where should I set the flags ?

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;
}
Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
  • Have you tried: *setWindowFlags(getWindowFlags() | Qt::FramelessWindowHint);* – hyde Nov 29 '13 at 17:49
  • Also make sure you do that to the top level window! – hyde Nov 29 '13 at 17:52
  • @hyde What do you mean by top level? The one on top? The first level Parent? The last level child? – Thomas Ayoub Nov 29 '13 at 18:01
  • I mean the widget without parent, IOW `NULL` parent. – hyde Nov 29 '13 at 18:19
  • @hyde it is not the main widget so it had a parent. I try to use this->setParent(NULL) but it didn't change the problem – Thomas Ayoub Nov 29 '13 at 18:28
  • It might be useful to add some code snippets and shows your widget hierarchy. But, do I understand correctly, that you have a widget which does have a parent, but is made to be a separate window with right flags? And it works, except you want to get rid of the window frame of the OS? – hyde Nov 29 '13 at 18:38
  • @hyde that's exactly that. The problem is that my code is quite big and I'm not sure I can do a snippet. I'll give a try. – Thomas Ayoub Nov 29 '13 at 20:33
  • Try to create a short example, really minimal test program from scratch. – hyde Nov 29 '13 at 20:36

2 Answers2

42

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. enter image description here

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

  window.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
  window.show();
}
sirian_ye
  • 610
  • 6
  • 11
  • Take a look at my result when setting flags to `Qt::Window | Qt::FramelessWindowHint` – Thomas Ayoub Nov 29 '13 at 17:35
  • hyde mentioned the same thing. I used exactly the same function you used "setWindowFlags(Qt::Window | Qt::FramelessWindowHint)" on my very top window. In the main function, see the edit in my post. – sirian_ye Nov 29 '13 at 22:09
  • Ah, I got you, you have another windows for displaying the video?. where do you initialize this control panel. I think you put the setWindowFlags(Qt::Window | Qt::FramelessWindowHint) on one of your inner widget. I attempted to do the setWindowFlags(Qt::Window | Qt::FramelessWindowHint) on my OpenGL widget, it will disappear as well. If you can post some code of your initialize process, it may help. – sirian_ye Nov 29 '13 at 22:21
  • What kind of object is your WoodPuppet ? A QWindow or a QWidget ? – Thomas Ayoub Dec 30 '13 at 14:59
  • 3
    If anyone is looking for the same answer but in `PyQt5`, it's `your_widget.setWindowFlag(QtCore.Qt.FramelessWindowHint, True)`. – Guimoute Sep 11 '21 at 13:59
0

This is what I did with qPysie6. I just directly use flags property in QML.

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

Joe
  • 811
  • 1
  • 8
  • 14