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. How do I find out values for QML enumerations in docs?
Forum Updated to NodeBB v4.3 + New Features

How do I find out values for QML enumerations in docs?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 151 Views 1 Watching
  • 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    Example case:
    I use the TextEdit QML type, and want to set horizontalAlignment and verticalAlignment from C++ via property binding.

    Docs state:

    Valid values for horizontalAlignment are:
    
    TextEdit.AlignLeft (default)
    TextEdit.AlignRight
    TextEdit.AlignHCenter
    TextEdit.AlignJustify
    
    Valid values for verticalAlignment are:
    
    TextEdit.AlignTop (default)
    TextEdit.AlignBottom
    TextEdit.AlignVCenter
    

    The values are not linked, nor is a C++-side Enumeration mentioned. How do I find out which values to use? What type should the Q_PROPERTY have?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lemons
      wrote on last edited by
      #2

      They should refer to the Qt AlignmentFlag enum.
      Therefore, you should be able to do something like this:

      Q_PROPERTY(int hAlign READ getHorizontalAlignment NOTIFY objectChanged)
      Q_PROPERTY(int vAlign READ getVerticalAlignment NOTIFY objectChanged)
      
      int MyClass::getHorizontalAlignment()
      {
          return Qt::AlignHCenter;
      }
      int MyClass::getVerticalAlignment()
      {
          return Qt::AlignBottom;
      }
      
      TextEdit {
          anchors.fill: parent
          text: "Hello World"
          horizontalAlignment: MyContextPropertyOrModel.hAlign
          verticalAlignment: MyContextPropertyOrModel.vAlign
      }
      
      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