Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions qt6/src/qml/ArrowListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,23 @@ FocusScope {
}
interactive: itemsView.count > maxVisibleItems
ScrollIndicator.vertical: ScrollIndicator { }
highlight: HighlightPanel {
highlight: Control {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接把HighlightPanel的根从Item改成Control是不是也可以,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里先确认一下“根”指哪个对象:

如果指 HighlightPanel.qml 的根(当前是 Item),不建议直接改成 Control。ColorSelector::findAndSetControlParent() 是从元素自身开始找第一个 Control 的,根改成 Control 后会停在自身;MenuItem / ItemDelegate / NavigationTitle 这些把 HighlightPanel 当 background 的场景就不再继承宿主 Control 的 hovered / pressed / disabled 状态。FlowStyle 里 highlightPanel.background 定义了 hovered 变体,本地最小 QML 对比同一个 hovered 宿主下,Item 根是 Hovered / #4099d0,Control 根变成 Normal / #308cc6,会有可见的 hover 高亮色变化。

如果指 ArrowListView.qml 的根 FocusScope,也不建议改:Control 不继承 FocusScope,键盘焦点/导航语义会变;Menu.qml 的根是 T.Menu / Popup,更无法改成 Control。

所以当前只在 Menu / ArrowListView 的 ListView.highlight 外包一层 Control,作用域最小;C++ 的 standardPalette 回退继续覆盖独立/窗口级无 Control 场景。若希望减少改动,可以只保留 C++ 回退、去掉这两处包裹,但不建议改公共组件的根类型。

visible: false // TODO listview's highlight is confict with Item's highlight.
outerShadowColor: null
innerShadowColor: null
hoverEnabled: false
scale: D.DTK.hasAnimation ? 0.9 : 1.0
Component.onCompleted: {
scale = 1.0
}
Behavior on scale {
NumberAnimation { duration: 100 }
}

// Keep the highlight panel under a Control so that its
// ColorSelector can resolve typed colors (e.g. D.Color.Highlight).
contentItem: HighlightPanel {
outerShadowColor: null
innerShadowColor: null
}
}
highlightFollowsCurrentItem: true
highlightMoveDuration: -1
Expand Down
16 changes: 11 additions & 5 deletions qt6/src/qml/Menu.qml
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,30 @@ T.Menu {
view.highlightMoveDuration: 50
view.highlightMoveVelocity: -1

view.highlight: HighlightPanel {
id: highlightRect
view.highlight: Control {
visible: false // TODO listview's highlight is confict with Item's highlight.
hoverEnabled: false
anchors.left: parent ? parent.left : undefined
anchors.right: parent ? parent.right : undefined
anchors.leftMargin: 0
anchors.rightMargin: 0
scale: D.DTK.hasAnimation ? 0.9 : 1.0

radius: DS.Style.menu.item.radius
outerShadowColor: null
innerShadowColor: null
Component.onCompleted: {
scale = 1.0
}
Behavior on scale {
NumberAnimation { duration: 100 }
}

// Keep the highlight panel under a Control so that its
// ColorSelector can resolve typed colors (e.g. D.Color.Highlight).
contentItem: HighlightPanel {
id: highlightRect
radius: DS.Style.menu.item.radius
outerShadowColor: null
innerShadowColor: null
}
}
}
Loader {
Expand Down
5 changes: 5 additions & 0 deletions src/private/dquickcontrolpalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,11 @@ QColor DQuickControlColorSelector::getColorOf(const DQuickControlPalette *palett
if (targetColor.isTypedColor()) {
if (m_control)
colorValue = targetColor.toColor(_d_getControlPalette(m_control));
else
// no control in the parent chain (e.g. popup/window context):
// fall back to the application-wide standard palette instead of
// returning an invalid color
colorValue = targetColor.toColor(DGuiApplicationHelper::standardPalette(state->controlTheme));
} else {
colorValue = targetColor.color();
}
Expand Down
Loading