質問編集履歴
5
改行を入れて見やすくした
test
CHANGED
File without changes
|
test
CHANGED
@@ -63,7 +63,8 @@
|
|
63
63
|
Shadow:[Active:#ff696969,Disabled:#ff000000,Inactive:#ff696969],
|
64
64
|
Highlight:[Active:#ff0078d7,Disabled:#ff0078d7,Inactive:#ff0078d7],
|
65
65
|
HighlightedText:[Active:#ffffffff,Disabled:#ff6d6d6d,Inactive:#ffffffff],
|
66
|
+
Link:[Active:#ff0000ff,Inactive:#ff0000ff],
|
66
|
-
Link
|
67
|
+
LinkVisited:[Active:#ffff00ff,Inactive:#ffff00ff],
|
67
68
|
AlternateBase:[Active:#ffe9e7e3,Disabled:#fff7f7f7,Inactive:#ffe9e7e3],
|
68
69
|
ToolTipBase:[Active:#ffffffdc,Disabled:#ffffffdc,Inactive:#ffffffdc],
|
69
70
|
ToolTipText:[Active:#ff000000,Disabled:#ff000000,Inactive:#ff000000],
|
4
'試したこと'の更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -50,7 +50,8 @@
|
|
50
50
|
//変更前
|
51
51
|
QPalette(resolve=0x77ffffa7fffdffff,"
|
52
52
|
WindowText:[Active:#ff000000,Disabled:#ff6d6d6d,Inactive:#ff000000],
|
53
|
-
Button:[Active:#fff0f0f0,Disabled:#fff0f0f0,Inactive:#fff0f0f0],
|
53
|
+
Button:[Active:#fff0f0f0,Disabled:#fff0f0f0,Inactive:#fff0f0f0],
|
54
|
+
Light:[Active:#ffffffff,Disabled:#ffffffff,Inactive:#ffffffff],
|
54
55
|
Midlight:[Active:#ffe3e3e3,Disabled:#fff7f7f7,Inactive:#ffe3e3e3],
|
55
56
|
Dark:[Active:#ffa0a0a0,Disabled:#ffa0a0a0,Inactive:#ffa0a0a0],
|
56
57
|
Mid:[Active:#ffa0a0a0,Disabled:#ffa0a0a0,Inactive:#ffa0a0a0],
|
3
補足のためのメニューバーの画像を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,23 +10,69 @@
|
|
10
10
|
|
11
11
|
### 試したこと
|
12
12
|
|
13
|
-
|
13
|
+
次のようにsetPalette()を使用しましたが、変化はありませんでした。
|
14
14
|
|
15
15
|
```c++
|
16
|
+
qDebug() << menuBar()->foregroundRole(); //ButtonText
|
17
|
+
qDebug() << menuBar()->backgroundRole(); //Button
|
16
|
-
|
18
|
+
qDebug() << menuBar()->palette(); //変更前のPalette
|
17
|
-
QMenu *const menu1 = new QMenu("test", menuBar);
|
18
|
-
menuBar->addMenu(menu1);
|
19
|
-
setMenuBar(menuBar);
|
20
19
|
|
20
|
+
QPalette palette;
|
21
|
-
|
21
|
+
palette.setColor(QPalette::ColorRole::Button, Qt::black);
|
22
|
-
qDebug() << menuWidget()->backgroundRole(); //QPalette::Button
|
23
|
-
qDebug() << menu1->backgroundRole(); //QPalette::Window
|
24
22
|
|
23
|
+
menuBar()->setPalette(palette);
|
24
|
+
|
25
|
-
menuBar->
|
25
|
+
qDebug() << menuBar()->palette(); //変更後のPalette
|
26
|
-
menuWidget()->setPalette(QPalette(QPalette::Button, Qt::lightGray)); //変更されない
|
27
|
-
menu1->setPalette(QPalette(QPalette::Window, Qt::lightGray)); //変更されない
|
28
26
|
```
|
29
|
-
|
27
|
+
出力は以下の通りでした。
|
28
|
+
```txt
|
29
|
+
//変更前
|
30
|
+
QPalette(resolve=0x0)
|
31
|
+
//変更後
|
32
|
+
QPalette(resolve=0x10000080000400,"Window:[Active:#ff000000,Disabled:#ff000000,Inactive:#ff000000]")
|
33
|
+
```
|
34
|
+
値は変わっていますが、メニューバーは変化がありませんでした。ほかにもQPalette::ColorRoleをWindowやBaseでやっても変化はありませんでした。
|
35
|
+
|
36
|
+
QWidgetクラスのドキュメントのQPalette項目を見てみると以下のようにありました。
|
37
|
+
> The default depends on the system environment. QApplication maintains a system/theme palette which serves as a default for all widgets. There may also be special palette defaults for certain types of widgets (e.g., on Windows Vista, all classes that derive from QMenuBar have a special default palette). You can also define default palettes for widgets yourself by passing a custom palette and the name of a widget to QApplication::setPalette(). Finally, the style always has the option of polishing the palette as it's assigned (see QStyle::polish()).
|
38
|
+
QMenuBarクラスには特別にデフォルトのQPaletteが設定されているらしい??そこで書いて通りに、QMenuBarのPaletteを上書きしたく、次のようにしました。
|
39
|
+
```C++
|
40
|
+
qDebug() << QApplication::palette("QMenuBar"); //変更前のQMenuBarのPalette
|
41
|
+
|
42
|
+
QPalette palette;
|
43
|
+
palette.setColor(QPalette::ColorRole::Button, Qt::black);
|
44
|
+
QApplication::setPalette(palette, "QMenuBar");
|
45
|
+
|
46
|
+
qDebug() << QApplication::palette("QMenuBar"); //変更後
|
47
|
+
```
|
48
|
+
しかし、メニューバーの色は変わりませんでした。出力は以下の通りです
|
49
|
+
```txt
|
50
|
+
//変更前
|
51
|
+
QPalette(resolve=0x77ffffa7fffdffff,"
|
52
|
+
WindowText:[Active:#ff000000,Disabled:#ff6d6d6d,Inactive:#ff000000],
|
53
|
+
Button:[Active:#fff0f0f0,Disabled:#fff0f0f0,Inactive:#fff0f0f0],Light:[Active:#ffffffff,Disabled:#ffffffff,Inactive:#ffffffff],
|
54
|
+
Midlight:[Active:#ffe3e3e3,Disabled:#fff7f7f7,Inactive:#ffe3e3e3],
|
55
|
+
Dark:[Active:#ffa0a0a0,Disabled:#ffa0a0a0,Inactive:#ffa0a0a0],
|
56
|
+
Mid:[Active:#ffa0a0a0,Disabled:#ffa0a0a0,Inactive:#ffa0a0a0],
|
57
|
+
Text:[Active:#ff000000,Disabled:#ff6d6d6d,Inactive:#ff000000],
|
58
|
+
BrightText:[Active:#ffffffff,Disabled:#ffffffff,Inactive:#ffffffff],
|
59
|
+
ButtonText:[Active:#ff000000,Disabled:#ff787878,Inactive:#ffa0a0a0],
|
60
|
+
Base:[Active:#ffffffff,Disabled:#fff0f0f0,Inactive:#ffffffff],
|
61
|
+
Window:[Active:#fff0f0f0,Disabled:#fff0f0f0,Inactive:#fff0f0f0],
|
62
|
+
Shadow:[Active:#ff696969,Disabled:#ff000000,Inactive:#ff696969],
|
63
|
+
Highlight:[Active:#ff0078d7,Disabled:#ff0078d7,Inactive:#ff0078d7],
|
64
|
+
HighlightedText:[Active:#ffffffff,Disabled:#ff6d6d6d,Inactive:#ffffffff],
|
65
|
+
Link:[Active:#ff0000ff,Inactive:#ff0000ff],LinkVisited:[Active:#ffff00ff,Inactive:#ffff00ff],
|
66
|
+
AlternateBase:[Active:#ffe9e7e3,Disabled:#fff7f7f7,Inactive:#ffe9e7e3],
|
67
|
+
ToolTipBase:[Active:#ffffffdc,Disabled:#ffffffdc,Inactive:#ffffffdc],
|
68
|
+
ToolTipText:[Active:#ff000000,Disabled:#ff000000,Inactive:#ff000000],
|
69
|
+
PlaceholderText:[Active:#80000000,Disabled:#80000000,Inactive:#80000000]")
|
70
|
+
//変更後
|
71
|
+
QPalette(resolve=0x0)
|
72
|
+
```
|
73
|
+
正しくセットされていない??
|
74
|
+
他にもmenuWidget()やQMenu自体のPaletteを変更したりしましたが、変更できませんでした。
|
75
|
+
|
30
76
|
|
31
77
|
### 補足情報(FW/ツールのバージョンなど)
|
32
78
|
|
2
セミコロンの付け忘れを修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,3 +32,7 @@
|
|
32
32
|
|
33
33
|
Desktop Qt 6.2.0 MSVC2019 64bit
|
34
34
|
|
35
|
+
メニューバーの背景色とは下のQt Creatorでいうと、「ファイル(F)」や「編集(E)」の背景のグレーの部分のことです。
|
36
|
+
|
37
|
+
![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-02-24/b2fe6446-2374-4531-adf9-b6cc76094b00.png)
|
38
|
+
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,9 +18,9 @@
|
|
18
18
|
menuBar->addMenu(menu1);
|
19
19
|
setMenuBar(menuBar);
|
20
20
|
|
21
|
-
qDebug() << menuBar->backgroundRole() //QPalette::Button
|
21
|
+
qDebug() << menuBar->backgroundRole(); //QPalette::Button
|
22
|
-
qDebug() << menuWidget()->backgroundRole() //QPalette::Button
|
22
|
+
qDebug() << menuWidget()->backgroundRole(); //QPalette::Button
|
23
|
-
qDebug() << menu1->backgroundRole() //QPalette::Window
|
23
|
+
qDebug() << menu1->backgroundRole(); //QPalette::Window
|
24
24
|
|
25
25
|
menuBar->setPalette(QPalette(QPalette::Button, Qt::lightGray)); //変更されない
|
26
26
|
menuWidget()->setPalette(QPalette(QPalette::Button, Qt::lightGray)); //変更されない
|