Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt remove title bar

Tags:

c++

window

qt

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;
}
like image 617
Thomas Ayoub Avatar asked Nov 29 '13 17:11

Thomas Ayoub


People also ask

How do I remove the title bar in Qt?

To remove the frame of any window using Qt you need to use the following piece of code: setWindowFlags(Qt::Window | Qt::FramelessWindowHint); Note that this will also cause the title bar of the window to be removed which means there will be no “close”, “minimize” and “maximize” buttons.

How do I hide a label in Qt?

In order to hide the label we use setHidden() method, this method allows user to set if the widget should be visible or hidden, it belongs to the QWidget class .


1 Answers

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();
}
like image 145
sirian_ye Avatar answered Sep 29 '22 08:09

sirian_ye