Qt5.4 QDialog窗体圆角时圆角透明背景是黑色的解决方法

在framebuffer、armlinux系统上使用Qt5.4时,设置QDialog窗体为圆角和透明背景后,发现圆角部分背景变为黑色。通过设置Qt::WA_TranslucentBackground和Qt::FramelessWindowHint属性,窗体被当作QWidget处理,导致QDialog的Qt::ApplicationModal置顶功能失效。解决这个问题并保持子窗口置顶的方法是关键。
部署运行你感兴趣的模型镜像

运行环境:framebuffer、armlinux系统、qt5.4
设置这两句
setAttribute(Qt::WA_TranslucentBackground);
setWindowFlags(Qt::FramelessWindowHint);

//通过这个接口可以发现

void MissionMark::PrintWindowFlags()
{
    QString text;
    Qt::WindowFlags flags = this->windowFlags();
    Qt::WindowFlags type = ( flags & Qt::WindowType_Mask);
    if (type == Qt::Window) {
        text = "Qt::Window";
    } else if (type == Qt::Dialog) {
        text = "Qt::Dialog";
    } else if (type == Qt::Widget) {
        text = "Qt::Widget";
    } else if (type == Qt::ForeignWindow) {
        text = "Qt::ForeignWindow";
    } else if (type == Qt::SubWindow) {
        text = "Qt::SubWindow";
    } else if (type == Qt::CoverWindow) {
        text = "Qt::CoverWindow";
    } else if (type == Qt::Desktop) {
        text = "Qt::Desktop";
    } else if (type == Qt::Sheet) {
        text = "Qt::Sheet";
    } else if (type == Qt::Drawer) {
        text = "Qt::Drawer";
    } else if (type == Qt::Popup) {
        text = "Qt::Popup";
    } else if (type == Qt::Tool) {
        text = "Qt::Tool";
    } else if (type == Qt::ToolTip) {
        text = "Qt::ToolTip";
    } else if (type == Qt::SplashScreen) {
        text = "Qt::SplashScreen";
    }

    if (flags & Qt::MSWindowsFixedSizeDialogHint)
        text += "\n| Qt::MSWindowsFixedSizeDialogHint";
    if (flags & Qt::X11BypassWindowManagerHint)
        text += "\n| Qt::X11BypassWindowManagerHint";
    if (flags & Qt::FramelessWindowHint)
        text += "\n| Qt::FramelessWindowHint";
    if (flags & Qt::NoDropShadowWindowHint)
        text += "\n| Qt::NoDropShadowWindowHint";
    if (flags & Qt::WindowTitleHint)
        text += "\n| Qt::WindowTitleHint";
    if (flags & Qt::WindowSystemMenuHint)
        text += "\n| Qt::WindowSystemMenuHint";
    if (flags & Qt::WindowMinimizeButtonHint)
        text += "\n| Qt::WindowMinimizeButtonHint";
    if (flags & Qt::WindowMaximizeButtonHint)
        text += "\n| Qt::WindowMaximizeButtonHint";
    if (flags & Qt::WindowCloseButtonHint)
        text += "\n| Qt::WindowCloseButtonHint";
    if (flags & Qt::WindowContextHelpButtonHint)
        text += "\n| Qt::WindowContextHelpButtonHint";
    if (flags & Qt::WindowShadeButtonHint)
        text += "\n| Qt::WindowShadeButtonHint";
    if (flags & Qt::WindowStaysOnTopHint)
        text += "\n| Qt::WindowStaysOnTopHint";
    if (flags & Qt::CustomizeWindowHint)
        text += "\n| Qt::CustomizeWindowHint";
    if (flags & Qt::MSWindowsOwnDC)
        text += "\n| Qt::MSWindowsOwnDC";
    if (flags & Qt::WindowMinMaxButtonsHint)
        text += "\n| Qt::WindowMinMaxButtonsHint";
    if (flags & Qt::MacWindowToolBarButtonHint)
        text += "\n| Qt::MacWindowToolBarButtonHint";
    if (flags & Qt::BypassGraphicsProxyWidget)
        text += "\n| Qt::BypassGraphicsProxyWidget";
    if (flags & Qt::WindowStaysOnBottomHint)
        text += "\n| Qt::WindowStaysOnBottomHint";
    if (flags & Qt::WindowFullscreenButtonHint)
        text += "\n| Qt::WindowFullscreenButtonHint";
    if (flags & Qt::WindowOkButtonHint)
        text += "\n| Qt::WindowOkButtonHint";
    if (flags & Qt::WindowCancelButtonHint)
        text += "\n| Qt::WindowCancelButtonHint";
    if (flags & Qt::WindowTransparentForInput)
        text += "\n| Qt::WindowTransparentForInput";
    if (flags & Qt::WindowDoesNotAcceptFocus)
        text += "\n| Qt::WindowDoesNotAcceptFocus";
    if (flags & Qt::WindowOverridesSystemGestures)
        text += "\n| Qt::WindowOverridesSystemGestures";
        
	qDebug()<<text;
}

设置 setWindowFlags(Qt::FramelessWindowHint)之前QDialog的windowFLags;

“Qt::Dialog
| Qt::WindowTitleHint
| Qt::WindowSystemMenuHint
| Qt::WindowCloseButtonHint
| Qt::WindowContextHelpButtonHint”

设置后
“Qt::Widget
| Qt::FramelessWindowHint”

可见它是把他当成了QWidget来处理的,所以这个地方会造成QDialog的Qt::ApplicationModal阻塞失效,并且也没有置顶了。

延伸资料:关于Qt如何保持子窗口显示在最上面的两种方式

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值