`
qimo601
  • 浏览: 3418034 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

Qt子窗口QMidSubwindow全屏出现的问题总结

    博客分类:
  • Qt
阅读更多

 

我的需求:想全屏一个子窗口QMidSubwindow,禁止显示最大化最小化和关闭按钮。

 

我开始尝试的是网上介绍的方法,把结果展现给大家一下,最后再总结:

 

方法1:QMidSubwindow直接调用showMaximized(),我的疑问在图片上,为啥我的禁止子窗口显示最大化、最小化、关闭按钮,没有成功呢???

源码:

    ExaminationForm *patientExamForm = new ExaminationForm();

    patientExamForm->setWindowTitle("病人检查");

 

    QMdiSubWindow *patientExamSubWindow = ui.mdiArea->addSubWindow(patientExamForm);

    //禁止子窗口显示最大化、最小化和关闭按钮

    patientExamSubWindow->setWindowFlags(Qt::WindowMinMaxButtonsHint&Qt::WindowCloseButtonHint);

    //最大化显示子窗口

    patientExamSubWindow->showMaximized();

 

结果图:

主窗口图

点击工具栏辐射图标,打开我的子窗口。结果如下:

 

 

方法2:调用showFullScreen()方法

解决过程1,直接调用showFullScreen()方法

源码:

 

    ExaminationForm *patientExamForm = new ExaminationForm();
    patientExamForm->setWindowTitle("病人检查");
    
    patientExamSubWindow->setWindowFlags(Qt::WindowMinMaxButtonsHint&Qt::WindowCloseButtonHint);
    patientExamSubWindow->showFullScreen();
 

结果

 

解决过程2,从网上知道

 写道

QT中窗口部件QWidget成员函数showFullScreen();是用于将窗口部件全屏显示,但是他只对窗口模式的部件有用。子窗口的特征是 Qt::SubWindow,不是独立的窗口。因此对其调用showFullScreen()无效。通过对对子窗口调 用:setWindowFlags(Qt::Dialog);或setWindowFlags(Qt::Window);将其设为窗口模式后,即可调用 showFullScreen();进行全屏显示了。
 

所以更改源码加上窗口标记 setWindowFlags

 

 QMdiSubWindow *patientExamSubWindow = ui.mdiArea->addSubWindow(patientExamForm);
    patientExamSubWindow->setWindowFlags(Qt::WindowMinMaxButtonsHint&Qt::WindowCloseButtonHint);
    //设置成窗口形式
    patientExamSubWindow->setWindowFlags(Qt::Window);
    patientExamSubWindow->showFullScreen();
 

 

 

解决过程3,最大化、最小化窗口、关闭按钮没消失,是因为设置窗口标记的时候不能累加,应该一次设定窗口标记。

预示源码改成这样

 

    ExaminationForm *patientExamForm = new ExaminationForm();
    patientExamForm->setWindowTitle("病人检查");

    QMdiSubWindow *patientExamSubWindow = ui.mdiArea->addSubWindow(patientExamForm);
    patientExamSubWindow->setWindowFlags(Qt::Window&Qt::WindowMinMaxButtonsHint&Qt::WindowCloseButtonHint);
    patientExamSubWindow->showFullScreen();
 

 

结果:

 

 

 

改成这样写patientExamSubWindow->setWindowFlags(Qt::Window&Qt::WindowMinMaxButtonsHint&Qt::WindowCloseButtonHint);

 只是解决了屏蔽子窗口的最大化等按钮问题,以及解决了让子窗口不跳出主窗口等问题(这个地方我也不懂)

但是最大的问题,为啥showFullScreen没起到作用呢,没最大化展现啊。。。。

 

 

到底是什么原因呢?

我这个子窗口也是顶级窗口也是非模态窗口啊,为啥showFullScreen不行呢。。。我正在考虑中。。。

 

 

//重新画以显示器尺寸大小画界面

navigationSubWindow->setGeometry(0,0,QApplication::desktop()->width(),QApplication::desktop()->height());

navigationSubWindow->show()

//窗口无frame无最大最小框,无框架就是没有标题栏,状态栏和边框。

setWindowFlags(Qt::FramelessWindowHint)

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics