激活子窗口后如何停止主窗口菜单变灰? [英] How to stop graying out of main window menu after activation of child window?

查看:34
本文介绍了激活子窗口后如何停止主窗口菜单变灰?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows 有一个特性:如果当前窗口没有被激活,这个窗口的主菜单看起来是禁用的(但实际上它只是灰色的,所以你可以点击这个菜单中的任何项目).切换到别的程序是可以的,但是到子窗口就不行了.

There is a feature in Windows: If current window is not activated, main menu of this window looks disabled (but in fact it is just grayed out, so you can click on any item in this menu). It is ok when you switch to another program, but it looks wrong when you go to child window.

即使使用标准记事本也很容易重现这种效果:

It is easy to reproduce this effect even with standard Notepad:

  • 将任何文本放入其中,
  • Ctrl+F
  • 现在您可以看到主菜单看起来已禁用,但您可以点击其中的任何项目.

问题如下:如何仅在我的程序中阻止这种效果?在我的程序(C++ 和 Qt)中,当用户转到儿童窗户.有没有办法阻止它?

The question is following: How to block this effect for my program only? In my program (C++ and Qt) I have the same graying out of all items in the main menu when user goes to child windows. Is there a way to stop it?

我没有在这里放任何代码,因为这种效果在大多数程序中都可以重现.但我希望可以更改我的 QMenuQMenuBar 的标志/属性来纠正这种行为.可能吗?

I do not put any code here, because this effect it reproducible in the most of programs. But I hope that it is possible to change flags/properties of my QMenu or QMenuBar to correct this behavior. Is it possible?

推荐答案

我们可以更正 QMenuBar 的调色板,以将处于非活动状态的文本颜色替换为处于活动状态的文本颜色.

We can correct a palette of the QMenuBar to substitute a text color in inactive state with text color in active state.

代码:

QPalette pal = pMenuBar->palette();
QColor col = pal.color(QPalette::Active, QPalette::ButtonText);
pal.setColor(QPalette::Inactive, QPalette::ButtonText, col);
pMenuBar->setPalette(pal);

之后用户将不会看到主菜单中的项目变灰,因为活动和非活动项目的文本颜色将相同.

After it user will not see graying out of items in a main menu, because text colors of active and inactive items will be the same.

(理论上有可能同一个item的active和inactive状态的背景颜色不同,所以也可以用同样的背景替换)

(Theoretically it is possible that background color of active and inactive states of the same item are different. So it might be reasanoble to make the same replacement for background too)

这篇关于激活子窗口后如何停止主窗口菜单变灰?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆