Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Change header icons changing page
Forum Updated to NodeBB v4.3 + New Features

Change header icons changing page

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 381 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    davidino
    wrote on 8 Jul 2018, 12:44 last edited by
    #1

    Goodmorning,
    I've realized inside the ApplicationView, a stackView so that I could change page. Aside that I'd like to add a header that changes its content according to the selected page. Consider that inside the header, I have some icons that are the same, others can change function when pressed, too.
    What is the best option to implement such thing?

    Thank you in advanced.

    G 1 Reply Last reply 8 Jul 2018, 22:17
    0
    • D davidino
      8 Jul 2018, 12:44

      Goodmorning,
      I've realized inside the ApplicationView, a stackView so that I could change page. Aside that I'd like to add a header that changes its content according to the selected page. Consider that inside the header, I have some icons that are the same, others can change function when pressed, too.
      What is the best option to implement such thing?

      Thank you in advanced.

      G Offline
      G Offline
      GrecKo
      Qt Champions 2018
      wrote on 8 Jul 2018, 22:17 last edited by
      #2

      The usual and flexible way to do that is a data driven solution.
      Don't add a button that will be added in the header, but define an action which the header will display how it wants.

      Create a custom page type with a property list<Actions> actions (a QQC2 Action can have a icon defined in it) and the display this actions with a Row + Repeater in the header.

      MyPage {
          title: "My Test Page"
          actions: [
              Action {
                  icon: /* ... */
                  onTriggered: doStuff()
              }
          ]
      }
      
      MyHeader {
          property MyPage currentPage
          Text {
              anchors.centerIn: parent
              text: currentPage ? currentPage.title : ""
          }
          Row {
              anchors.right: parent.right
              Repeater {
                  model: currentPage ? currentPage.actions
                  delegate: MyActionDelegate {
                      // display the icon in it, call the action.triggered method in the onClicked, ...
                  }
          }
      }
      

      Quick and dirty positionning, do better than that. But the idea is here.
      You can add more feature as needed.
      Add a visible property in the action and follow it in the delegate, respect the enabled property too.
      Add a back button in the header to pop the stackview. You could add a way for the currentPage to prevent going back, et cetera, et cetera.

      1 Reply Last reply
      0

      1/2

      8 Jul 2018, 12:44

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved