在Qml中创建类似kicker的子菜单
我使用的是kde plasmoid。它是一个类似kicker的应用程序菜单,我试图在单击主菜单中的一个项目时打开一个子菜单,如图所示: 但我能做的就是: 如何打开plasmoid主项之外的子菜单。考虑到子菜单是ListView,也是主菜单。 这是菜单的“调用”:在Qml中创建类似kicker的子菜单,qml,kde,plasmoid,Qml,Kde,Plasmoid,我使用的是kde plasmoid。它是一个类似kicker的应用程序菜单,我试图在单击主菜单中的一个项目时打开一个子菜单,如图所示: 但我能做的就是: 如何打开plasmoid主项之外的子菜单。考虑到子菜单是ListView,也是主菜单。 这是菜单的“调用”: ListDelegate { id: recentitemsItem text: i18n("Recent Items")
ListDelegate {
id: recentitemsItem
text: i18n("Recent Items")
highlight: delegateHighlight
PlasmaComponents.Label {
id: submenuArrow
text: "⏵"
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
}
onClicked: {
subMenu.visible = !subMenu.visible
}
}
Item {
id: subMenu
visible : false
width: units.gridUnit * 14
height: units.gridUnit * 43
x : units.gridUnit * 16
y : aboutComputerItem.height + separatorItem.height + systemsettingsItem.height + appStoreItem.height + separatorItem1.height + recentitemsItem.height
PlasmaComponents.Label {
id: applications
enabled: false
text: "Applications"
}
ListView {
id: row
anchors.top: applications.bottom
width: parent.width
height: parent.height
model: Kicker.RecentUsageModel {
favoritesModel: globalFavorites
}
delegate: ListDelegate {
height: 24
width: parent.width
highlight: delegateHighlight
onClicked: if(model.url == undefined){
executable.exec("gtk-launch " + model.favoriteId);
}
else {executable.exec("xdg-open '" + model.url + "'");
}
PlasmaCore.IconItem {
id: icon
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: 10
width: 16
height: width
visible: true
source: model.decoration
}
PlasmaComponents.Label {
id: label
enabled: true
anchors.verticalCenter: icon.verticalCenter
anchors.left : icon.right
anchors.leftMargin: 10
width: parent.width
verticalAlignment: Text.AlignVCenter
textFormat: Text.PlainText
wrapMode: Text.NoWrap
elide: Text.ElideRight
text: model.display
}
}
}
}
这是菜单:
ListDelegate {
id: recentitemsItem
text: i18n("Recent Items")
highlight: delegateHighlight
PlasmaComponents.Label {
id: submenuArrow
text: "⏵"
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
}
onClicked: {
subMenu.visible = !subMenu.visible
}
}
Item {
id: subMenu
visible : false
width: units.gridUnit * 14
height: units.gridUnit * 43
x : units.gridUnit * 16
y : aboutComputerItem.height + separatorItem.height + systemsettingsItem.height + appStoreItem.height + separatorItem1.height + recentitemsItem.height
PlasmaComponents.Label {
id: applications
enabled: false
text: "Applications"
}
ListView {
id: row
anchors.top: applications.bottom
width: parent.width
height: parent.height
model: Kicker.RecentUsageModel {
favoritesModel: globalFavorites
}
delegate: ListDelegate {
height: 24
width: parent.width
highlight: delegateHighlight
onClicked: if(model.url == undefined){
executable.exec("gtk-launch " + model.favoriteId);
}
else {executable.exec("xdg-open '" + model.url + "'");
}
PlasmaCore.IconItem {
id: icon
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: 10
width: 16
height: width
visible: true
source: model.decoration
}
PlasmaComponents.Label {
id: label
enabled: true
anchors.verticalCenter: icon.verticalCenter
anchors.left : icon.right
anchors.leftMargin: 10
width: parent.width
verticalAlignment: Text.AlignVCenter
textFormat: Text.PlainText
wrapMode: Text.NoWrap
elide: Text.ElideRight
text: model.display
}
}
}
}
这个问题的一个答案是像这样使用
PlasmaCore.ToolTiArea{}
:
import org.kde.plasma.core 2.0 as PlasmaCore
ListDelegate {
id: recentitemsItem
text: i18n("Recent Items")
highlight: delegateHighlight
PlasmaCore.ToolTipArea {
id: toolTip
anchors.fill: parent
active: true
interactive : true
timeout : -1
location: PlasmaCore.Types.LeftEdge
mainItem: toolTipDelegate
}
onClicked: {
toolTip.showToolTip()
}
}
并将以下代码设置为main项:toolTipDelegate
Item {
id: toolTipDelegate
width: units.gridUnit * 16
height: units.gridUnit * 40
visible: false
ListView {
id: row
width: parent.width
height: parent.height
model: Kicker.RecentUsageModel {
favoritesModel: globalFavorites
}
delegate: ListDelegate {
height: 24
width: parent.width
highlight: delegateHighlight
onClicked: if(model.url == undefined){
executable.exec("gtk-launch '" + model.favoriteId + "'");
}
else {executable.exec("xdg-open '" + model.url + "'");
}
PlasmaCore.IconItem {
id: icon
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: 10
width: 16
height: width
visible: true
source: model.decoration
}
PlasmaComponents.Label {
id: label
enabled: true
anchors.verticalCenter: icon.verticalCenter
anchors.left : icon.right
anchors.leftMargin: 10
width: parent.width
verticalAlignment: Text.AlignVCenter
textFormat: Text.PlainText
wrapMode: Text.NoWrap
elide: Text.ElideRight
text: model.display
}
}
}
}
然后,每当鼠标悬停在最近的项目上或被单击时,都会打开一个带有listview(我想要的菜单)的工具提示窗口。这个问题的一个答案是使用PlasmaCore.ToolTiprea{}如下:
import org.kde.plasma.core 2.0 as PlasmaCore
ListDelegate {
id: recentitemsItem
text: i18n("Recent Items")
highlight: delegateHighlight
PlasmaCore.ToolTipArea {
id: toolTip
anchors.fill: parent
active: true
interactive : true
timeout : -1
location: PlasmaCore.Types.LeftEdge
mainItem: toolTipDelegate
}
onClicked: {
toolTip.showToolTip()
}
}
并将以下代码设置为main项:toolTipDelegate
Item {
id: toolTipDelegate
width: units.gridUnit * 16
height: units.gridUnit * 40
visible: false
ListView {
id: row
width: parent.width
height: parent.height
model: Kicker.RecentUsageModel {
favoritesModel: globalFavorites
}
delegate: ListDelegate {
height: 24
width: parent.width
highlight: delegateHighlight
onClicked: if(model.url == undefined){
executable.exec("gtk-launch '" + model.favoriteId + "'");
}
else {executable.exec("xdg-open '" + model.url + "'");
}
PlasmaCore.IconItem {
id: icon
anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: 10
width: 16
height: width
visible: true
source: model.decoration
}
PlasmaComponents.Label {
id: label
enabled: true
anchors.verticalCenter: icon.verticalCenter
anchors.left : icon.right
anchors.leftMargin: 10
width: parent.width
verticalAlignment: Text.AlignVCenter
textFormat: Text.PlainText
wrapMode: Text.NoWrap
elide: Text.ElideRight
text: model.display
}
}
}
}
然后,每当鼠标悬停在最近的项目上或被单击时,都会打开一个带有listview(我想要的菜单)的工具提示窗口