0

I show a dialog in my qt application on menu action click window is appearing perfectly but I want to hide its title bar as it is just a sub-window inside main window.

I tried :

this->setWindowFlags(Qt::Window |Qt::FramelessWindowHint);

In dialog constructor:

ui->setupUi(this);
this->setWindowState (Qt::WindowActive);
setWindowModality(Qt::ApplicationModal);
setAttribute (Qt::WA_DeleteOnClose);
this->setWindowFlags(Qt::Window |Qt::FramelessWindowHint) ; // 

This does remove the title bar but it also hides the main window, which is bad for my application.

How can I hide dialog title bar without disturbing the base main window of the application?

jww
  • 97,681
  • 90
  • 411
  • 885
Deepti
  • 119
  • 4
  • 12
  • 2
    Possible duplicate of [QDialog remove title bar](https://stackoverflow.com/q/30181630/608639). – jww Dec 09 '19 at 23:02

2 Answers2

4
 QDialog *dialog(new QDialog /* this should be your dialog class youve created obviously*/));
 dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
 dialog->show();
AngryDuck
  • 4,358
  • 13
  • 57
  • 91
1

You're missing the CustomizeWindowHint.

As you can see from the source code here (line 1035) for QWidget, it decides what to do depending upon that flag. So I suggest trying this: -

setWindowFlags(Qt::Window | Qt::CustomizeWindowHint); 
TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85
  • ur suggestion is working in same way as this->setWindowFlags(Qt::Window |Qt::FramelessWindowHint) , it does hides the titlebar of the window but also dislocates the mainwindow of the application. – Deepti Sep 25 '14 at 10:16
  • thanx ur answer is fine but it is not right for my application because i want to hide the title bar of the "dialog" and not a window. your answer works fine with mainwindow widget – Deepti Sep 25 '14 at 10:32