【问题标题】:listview doesn't appear in TabGroup QML?列表视图没有出现在 TabGroup QML 中?
【发布时间】:2012-03-07 13:00:10
【问题描述】:

如何使 QML 中的列表视图出现在选项卡中。我在 N9(Meego) 的应用程序中使用了代码,但现在我需要在 Symbian 中使用它。当我将它从 meego 转换为 symbian 时,我做了一些更改,但没有出现列表视图。请提供任何帮助。 注意:当我不使用标签时,会出现相同的列表视图!!!

我的代码:

import QtQuick 1.1
import com.nokia.symbian 1.1
import com.nokia.extras 1.1
import "UIConstants.js" as UiConstants

Page {
  id: mainpage

       orientationLock: PageOrientation.LockPortrait



    tools:
    TabBar {
           // platformStyle: TabButtonStyle { }
            TabButton {
           text: "Tab 1"
                tab: tab1

            }
            TabButton {
                text: "Tab 2"

                tab: tab2

            }
            TabButton {
                text: "Tab 3"
                tab: tab3

            }
            TabButton {
               text: "Tab 4"
                tab: tab4

            }
                       }



    TabGroup {
             id: tabGroup

             PageStack {
                id: tab1
                Component.onCompleted: tab1.push(listPage)

             // define the content for tab 1
             Page {
                 id: listPage


                   Item {
                             id: testList
                            anchors.fill: parent

                              function openFile(file) {
                                 var component = Qt.createComponent(file)

                                 if (component.status == Component.Ready) {
                                     mainWindow.pageStack.push(component);
                                     console.log("Loading component okay");
                                 }
                                 else {
              console.log("Error loading component:", component.errorString());
                                 }
                             }

                             ListModel {
                                 id: pagesModel

                                 ListElement {
                                     page: "InfoBannerPage.qml"
                                     title: "InfoBanner"
                                     subtitle: "Info Banner"
                                 }

                                 ListElement {
                                     page: "RatingIndicator.qml"
                                     title: "RatingIndicator"
                                     subtitle: "Indicates ratings"
                                 }

                             }

                             ListView {
                                 id: list
                                 model: pagesModel
                                 anchors.fill: parent

                                 delegate: ListItem {
                                     id: listItem

                                     platformInverted: mainWindow.childrenInverted

                                     Row {
                                         id: listItemRow


                                         Column {

                                             ListItemText {
                                                 id: mainText
                                               //  width: listItemRow.width
                                                 role: "Title"
                                                 text: title

                                             }

                                             ListItemText {
                                                 id: subText
                                             //   width: listItemRow.width
                                                 role: "SubTitle"
                                                 text: subtitle
                                                 visible: text != ""

                                             }
                                         }
                                     }

                                     onClicked: { testList.openFile(page); }
                                 } // listItem
                             } // listView

                             ScrollDecorator {
                                 flickableItem: listPage
                                 platformInverted: mainWindow.childrenInverted
                             }
                         } // item
                     } // page
   }



             Page {
                 id: tab2

             }
             Page {
                 id: tab3

             }
             Page {
            id: tab4

        }

    }

}

【问题讨论】:

    标签: qt listview tabs qml


    【解决方案1】:

    您的布局有问题。

    工作一:

    import QtQuick 1.1
    import com.nokia.symbian 1.1
    import com.nokia.extras 1.1
    
    Page {
      id: mainpage
    
           orientationLock: PageOrientation.LockPortrait
    
    
    
    //    tools:
        TabBar {
            id: tabBar
            anchors {top: parent.top }
               // platformStyle: TabButtonStyle { }
                TabButton {
               text: "Tab 1"
                    tab: tab1
    
                }
                TabButton {
                    text: "Tab 2"
    
                    tab: tab2
    
                }
                TabButton {
                    text: "Tab 3"
                    tab: tab3
    
                }
                TabButton {
                   text: "Tab 4"
                    tab: tab4
    
                }
                           }
    
    
    
        TabGroup {
                 id: tabGroup
                 anchors {top: tabBar.bottom; bottom: parent.bottom}
    
                 PageStack {
                    id: tab1
                    Component.onCompleted: tab1.push(listPage)
    
                 // define the content for tab 1
                 Page {
                     id: listPage
                     anchors.fill: parent
    
    
                       Item {
                                 id: testList
                                anchors.fill: parent
    
                                  function openFile(file) {
                                     var component = Qt.createComponent(file)
    
                                     if (component.status == Component.Ready) {
                                         mainWindow.pageStack.push(component);
                                         console.log("Loading component okay");
                                     }
                                     else {
                  console.log("Error loading component:", component.errorString());
                                     }
                                 }
    
                                 ListModel {
                                     id: pagesModel
    
                                     ListElement {
                                         page: "InfoBannerPage.qml"
                                         title: "InfoBanner"
                                         subtitle: "Info Banner"
                                     }
    
                                     ListElement {
                                         page: "RatingIndicator.qml"
                                         title: "RatingIndicator"
                                         subtitle: "Indicates ratings"
                                     }
    
                                 }
    
                                 ListView {
                                     id: list
                                     model: pagesModel
                                     anchors.fill: parent
    
                                     delegate: ListItem {
                                         id: listItem
    
    //                                     platformInverted: mainWindow.childrenInverted
    
                                         Row {
                                             id: listItemRow
                                             anchors.fill: listItem.paddingItem
    
    
                                             Column {
    
                                                 ListItemText {
                                                     id: mainText
                                                   //  width: listItemRow.width
                                                     role: "Title"
                                                     text: title
    
                                                 }
    
                                                 ListItemText {
                                                     id: subText
                                                 //   width: listItemRow.width
                                                     role: "SubTitle"
                                                     text: subtitle
                                                     visible: text != ""
    
                                                 }
                                             }
                                         }
    
                                         onClicked: { testList.openFile(page); }
                                     } // listItem
                                 } // listView
    
                                 ScrollDecorator {
    //                                 flickableItem: listPage
    //                                 platformInverted: mainWindow.childrenInverted
                                 }
                             } // item
                         } // page
       }
    
    
    
                 Page {
                     id: tab2
    
                 }
                 Page {
                     id: tab3
    
                 }
                 Page {
                id: tab4
    
            }
    
        }
    }
    

    【讨论】:

    • 但是有一个新问题。似乎该项目不可点击?如果所有项目都没有出现在屏幕上,你能帮我吗?如果我想让列表滚动?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多