PDA

View Full Version : Diasble close button on a QDialog



Krish_ng
16th July 2007, 10:40
I hav created a Dialog ...I want to disable the close button on the dialog...

guilugi
16th July 2007, 10:46
Hello,

You have to use setWindowFlags() method, and I think you'll have to omit this particular flag :

Qt::WindowSystemMenuHint

Krish_ng
16th July 2007, 10:57
I have used designer to create the dialog. i hav used setContextMenuPolicy(Qt::NoContextMenu) to disable the maximize,minimize and close buttons.The ui file works fine for Windows OS but on Linux i am getting the close button on the dialog..Is there any option in the designer to remove the close button

rajesh
16th July 2007, 11:27
use m_pCloseBtn->setEnabled(false);

Krish_ng
16th July 2007, 11:40
Its not the qPushButton the clse,maximize,minimize button the Dialog

rajesh
16th July 2007, 12:12
you write following code, this will not disable but don't close your application.


void MyWindow::closeEvent(QCloseEvent *event)
{
event->ignore();
}

Krish_ng
16th July 2007, 12:20
I have used designer to create the dialog. i hav used setContextMenuPolicy(Qt::NoContextMenu) to make the maximize,minimize and close buttons invisble.The ui file works fine for Windows OS but on Linux the close button on the dialog is visible ..Is there any option in the designer to remove the close button...Sorry for using the term disable its actually visiblity.....

rajesh
16th July 2007, 12:28
this following code working for me on window.this code removing "X"button from title. I dont know it work on unix or not.

setWindowFlags(Qt::FramelessWindowHint);
setWindowFlags(Qt::WindowTitleHint);
setWindowTitle(tr("Virtual Development Board"));

Krish_ng
16th July 2007, 13:37
U r code works fine. But i do not get the title bar.Is there any way to hav the title bar with close button only..The maximize and minimize buttons on the MainWindow should be invisible....

rajesh
16th July 2007, 14:10
see the example code Window Flags Example: from
http://doc.trolltech.com/4.3/widgets-windowflags.html
this example code working fine on windows. you test this on linux, in this example depend on different check box it showing minimize , maximize and close button, and none of these also.
see void ControllerWindow::updatePreview() in example.

Krish_ng
16th July 2007, 15:57
I tested the code given in the website..It has solved my problem.I hav another one.I need a Dialog that has no close button on the dialog but has a titlebar...I tried using FramelessWindowHint but titlebar is not visible...Suggest some approach where i can hav a titlebar with no close button.

rajesh
16th July 2007, 16:11
after FramelessWindowHint ,use WindowTitleHint then only titlebar will be visible


setWindowFlags(Qt::FramelessWindowHint);
setWindowFlags(Qt::WindowTitleHint);

Krish_ng
17th July 2007, 05:23
I tried with the code given by you.It gives a frameless window with no titlebar and the I tried with option setWindowFlags(Qt::Tool|Qt::FramelessWindowHint|Qt ::WindowTitleHint).Still i am not able to get the title bar with no close,max,min button.