Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Inheriting QtQuick Item from C++
Qt 6.11 is out! See what's new in the release blog

Inheriting QtQuick Item from C++

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 495 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.
  • M Offline
    M Offline
    maydin
    wrote on last edited by
    #1

    In QtQuickControls there is a QML type called Dialog. Example:

    Dialog {
        parent: ApplicationWindow.overlay
    
        x: (parent.width - width) / 2
        y: (parent.height - height) / 4
        width: Math.min(parent.width, parent.height) / 3 * 2
        modal: true
        focus: true
        standardButtons: Dialog.Yes | Dialog.No
        }
    }
    

    I want to inherit this class and create my own buttons. Example "customButtons: Dialog.Button1 | Dialog.Button2"

    I have to do this in C++ since I must use enums. I can create flags like "Dialog.Ok" but I could not merge them with Dialog.

    My goal is changing this type to something I want. I dont want to write buttons explicitly like this everytime I use this type.

    CustomDialog {
            id: customDialog
    
            title: "Dialog Title"
    
            footer: DialogButtonBox {
                Button {
                    text: qsTr("Button1")
                    DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
                }
                Button {
                    text: qsTr("Button2")
                    DialogButtonBox.buttonRole: DialogButtonBox.RejectRole
                }
            }
    }
    
    1 Reply Last reply
    0
    • T Offline
      T Offline
      TobbY
      wrote on last edited by
      #2

      @maydin said in Inheriting QtQuick Item from C++:

      customButtons

      Hi,
      Please look at this for creating reusable custom buttons in QML.
      https://www.ics.com/blog/creating-qml-controls-scratch

      1 Reply Last reply
      0

      • Login

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