Results 1 to 2 of 2

Thread: overriding a property fixed by an external component

  1. #1
    Join Date
    Sep 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default overriding a property fixed by an external component

    I want to ovverride the height value for the image defined in a external PictureBox.qml file:

    Qt Code:
    1. import QtQuick 2.0
    2.  
    3. FocusScope {
    4. id: container
    5. ...
    6. Column {
    7. id: column
    8. ...
    9. Image {
    10. id: icon
    11. width: parent.width; height: 150
    12. ...
    To copy to clipboard, switch view to plain text mode 

    this code is called in Main.qml in this way:

    Qt Code:
    1. Component {
    2. id: userDelegate
    3.  
    4. PictureBox {
    5. ???
    6. ...
    To copy to clipboard, switch view to plain text mode 

    how can I override height value for the Image element, without touching PictureBox.qml code?

  2. #2
    Join Date
    Sep 2016
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: overriding a property fixed by an external component

    You can´t access internal properties in the children of the components because of scope, the tool provided by QML to access internal properties are "property aliases", that way your PictureBox.qml must contain a single line in the root element with the structure: "property alias name: id.property"

    Qt Code:
    1. import QtQuick 2.0
    2.  
    3. FocusScope {
    4. id: container
    5. propery alias iconHeight: icon.height //alias
    6. ...
    7. Column {
    8. id: column
    9. ...
    10. Image {
    11. id: icon
    12. width: parent.width; height: 150
    13. ...
    To copy to clipboard, switch view to plain text mode 

    and your Main would access that property like this:

    Qt Code:
    1. Component {
    2. id: userDelegate
    3.  
    4. PictureBox {
    5. iconHeight: 100
    6. ...
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 3
    Last Post: 2nd April 2016, 11:46
  2. Replies: 1
    Last Post: 24th November 2014, 08:28
  3. Destructor overriding
    By Daylight in forum Qt Programming
    Replies: 13
    Last Post: 1st March 2013, 11:05
  4. Replies: 4
    Last Post: 27th August 2012, 19:27
  5. Overriding drawRubberBand()
    By andrew.nguyen in forum Qwt
    Replies: 3
    Last Post: 21st April 2010, 06:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.