Qt之QDialog 设置Qt::FramelessWindowHint后窗口不显示

44 篇文章 202 订阅 ¥29.90 ¥99.00

简述

        QDialog自带的标题栏或者样式可能不是我们想要的,当我们打算重写标题栏或者去掉标题栏或者更改为圆角窗体时我们通常是使用Qt::FramelessWindowHint先去掉标题栏,但是这里会有一个问题:

    // 方式一不显示窗口
    QDialog *p1 = new QDialog(this);
    p1->setWindowFlags(Qt::FramelessWindowHint);
    p1->show();

    // 方式二显示窗口
    QDialog *p2 = new QDialog(this, Qt::FramelessWindowHint);
    p2->show();

源码

/*!
  Constructs a dialog with parent \a parent.

  A dialog is always a top-level widget, but if it has a parent, its
  default location is centered on top of the parent. It will also
  share the parent's taskbar entry.

  The widget flags \a f are passed on to the QWidget constructor.
  If, for example, you don't want a What's This button in the title bar
  of the dialog, pass Qt::WindowTitleHint | Qt::WindowSystemMenuHint in \a f.

  \sa QWidget::setWindowFlags()
*/

QDialog::QDialog(QWidget *parent, Qt::Wi
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Qt 中,可以使用 QPropertyAnimation 类来实现子窗口透明度的动画效果。具体步骤如下: 1. 在子窗口类中添加一个成员变量,用于保存透明度的值。 2. 在构造函数中设置窗口的属性,使其具有窗口透明度,代码如下: ``` setAttribute(Qt::WA_TranslucentBackground); setWindowFlags(Qt::FramelessWindowHint | Qt::Tool); ``` 3. 在子窗口类中添加一个方法,用于设置窗口的透明度,代码如下: ``` void setOpacity(qreal opacity) { m_opacity = opacity; setWindowOpacity(opacity); } ``` 4. 使用 QPropertyAnimation 类创建一个动画对象,将子窗口的透明度作为动画属性,代码如下: ``` QPropertyAnimation *animation = new QPropertyAnimation(this, "opacity"); animation->setDuration(1000); animation->setStartValue(0.0); animation->setEndValue(1.0); animation->start(); ``` 5. 启动动画。 完整代码示例: ``` #include <QDialog> #include <QPropertyAnimation> class MyDialog : public QDialog { public: MyDialog(QWidget *parent = 0) : QDialog(parent) , m_opacity(1.0) { setAttribute(Qt::WA_TranslucentBackground); setWindowFlags(Qt::FramelessWindowHint | Qt::Tool); } void setOpacity(qreal opacity) { m_opacity = opacity; setWindowOpacity(opacity); } private: qreal m_opacity; }; int main(int argc, char *argv[]) { QApplication app(argc, argv); MyDialog dialog; dialog.show(); QPropertyAnimation *animation = new QPropertyAnimation(&dialog, "opacity"); animation->setDuration(1000); animation->setStartValue(0.0); animation->setEndValue(1.0); animation->start(); return app.exec(); } ``` 以上代码演示了如何创建一个透明度动画的子窗口,并在启动时开始动画效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ilson_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值