首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Qml中创建一个类似kicker的子菜单

在Qml中创建一个类似kicker的子菜单
EN

Stack Overflow用户
提问于 2020-12-05 01:45:22
回答 1查看 176关注 0票数 1

我的usage.It是一个类似kicker的应用程序菜单,当我点击主菜单中的一个项目时,我正在尝试打开一个子菜单,如图所示:

但我能做的就是:

如何打开plasmoid.Take主项之外的子菜单,并考虑到该子菜单和主菜单一样都是ListView。这就是菜单的“召唤”:

代码语言:javascript
复制
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
                    
                }
        }

这是菜单:

代码语言:javascript
复制
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
                }       
        }
    }
 
}
EN

回答 1

Stack Overflow用户

发布于 2020-12-08 01:51:28

这个问题的一个解决方案是像这样使用PlasmaCore.ToolTipArea{}

代码语言:javascript
复制
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()
             }
         }

并将以下代码设置为mainItem: toolTipDelegate

代码语言:javascript
复制
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
                               }          
                        }
               
                
                    } 
                }

然后,每当鼠标悬停在Recent Items项上或被单击时,都会打开一个带有列表视图(我想要的菜单)的工具提示窗口。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65148277

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档