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. Locate QML Properties
QtWS25 Last Chance

Locate QML Properties

Scheduled Pinned Locked Moved QML and Qt Quick
qmltexteditdocs
9 Posts 4 Posters 3.3k 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.
  • W Offline
    W Offline
    whitecastleroad
    wrote on last edited by
    #1

    I am struggling trying to use the QML interface. I have run into countless properties that exist in the C++ API that do not seem to exist in QML. I would like to know if there is a way to figure out this information when it is never seems to be addressed in the docs. Does this mean the properties or methods are simply not exposed to the XML interface, or is there something I am missing. A specific example is QTextEdit::setTabStopWidth(). Is there a way to set this value in QML?

    VStevenPV 1 Reply Last reply
    0
    • W whitecastleroad

      I am struggling trying to use the QML interface. I have run into countless properties that exist in the C++ API that do not seem to exist in QML. I would like to know if there is a way to figure out this information when it is never seems to be addressed in the docs. Does this mean the properties or methods are simply not exposed to the XML interface, or is there something I am missing. A specific example is QTextEdit::setTabStopWidth(). Is there a way to set this value in QML?

      VStevenPV Offline
      VStevenPV Offline
      VStevenP
      wrote on last edited by VStevenP
      #2

      @whitecastleroad If I understand correctly, same-named QtQuick Components and Qt Widgets do not have the same API. Often, the QtQuick version has fewer features/is simpler, to make programming simpler.

      My approach is the following: The context-sensitive help in QtCreator is fairly accurate. You can hit F1 on the name of any QtQuick Component in your QML code, and as long as there is no syntax error in your code, you'll get to see all the truly available properties.

      If it turns out that the QtQuick Component is not sufficient for your needs, you can always create a new C++ class that inherits from a Qt Widget in which you are interested (in this case, QTextEdit), give it your own name, and expose it to be used in QML using the typical process of using the Q_OBJECT macro in your class header file and calling qmlRegisterType() in main.cpp to make your new class available to QML.

      • VStevenP
      1 Reply Last reply
      0
      • W Offline
        W Offline
        whitecastleroad
        wrote on last edited by p3c0
        #3

        @VStevenP
        Thank you, that is a good idea - I never thought about extending an existing object and exposing it to QtQuick. Otherwise, in the situation I mentioned above, is there any way to get a C++ QTextEdit object pointer for the TextEdit component in the QML file?

        Something along these lines:

           QObject *o = engine.rootObjects().first()->findChild<QObject*>("rich");
            if (o) {
                QQuickItem *item = qobject_cast<QQuickItem*>(o);
                if (item) {
                    qDebug() << "got item";
                    QTextEdit *rich = qobject_cast<QTextEdit*>(o);  //this does not work
                    if (rich) {
                        qDebug() << "got rich";
                    }
                }
        
        p3c0P J 2 Replies Last reply
        0
        • W whitecastleroad

          @VStevenP
          Thank you, that is a good idea - I never thought about extending an existing object and exposing it to QtQuick. Otherwise, in the situation I mentioned above, is there any way to get a C++ QTextEdit object pointer for the TextEdit component in the QML file?

          Something along these lines:

             QObject *o = engine.rootObjects().first()->findChild<QObject*>("rich");
              if (o) {
                  QQuickItem *item = qobject_cast<QQuickItem*>(o);
                  if (item) {
                      qDebug() << "got item";
                      QTextEdit *rich = qobject_cast<QTextEdit*>(o);  //this does not work
                      if (rich) {
                          qDebug() << "got rich";
                      }
                  }
          
          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @whitecastleroad Yes. Since TextEdit inherits Item you will have to cast it to QQuickItem instead of QTextEdit.

          P.S: The new forum's editor follows MarkDown markup language. so you can follow its rules. For eg. to post code put it inside ```(3 backticks).

          157

          VStevenPV 1 Reply Last reply
          0
          • p3c0P p3c0

            @whitecastleroad Yes. Since TextEdit inherits Item you will have to cast it to QQuickItem instead of QTextEdit.

            P.S: The new forum's editor follows MarkDown markup language. so you can follow its rules. For eg. to post code put it inside ```(3 backticks).

            VStevenPV Offline
            VStevenPV Offline
            VStevenP
            wrote on last edited by
            #5

            @p3c0 I have a feeling this may not help him, though, because if he has to cast it to a QQuickItem, he will be unable to call setTabStopWidth on that pointer.

            @whitecastleroad Basically, I think p3co's response explains it all. He explains that QML TextEdit inherits from QQuickItem, not QTextEdit. This is the evidence they are not objects of the same class, despite some similarity in properties available.

            1 Reply Last reply
            0
            • W Offline
              W Offline
              whitecastleroad
              wrote on last edited by
              #6

              @p3c0 @VStevenP Thanks to both of you. I will extend a QTextEdit as suggested above. Sounds like a good exercise for a Qt noob anyway :)

              1 Reply Last reply
              0
              • W whitecastleroad

                @VStevenP
                Thank you, that is a good idea - I never thought about extending an existing object and exposing it to QtQuick. Otherwise, in the situation I mentioned above, is there any way to get a C++ QTextEdit object pointer for the TextEdit component in the QML file?

                Something along these lines:

                   QObject *o = engine.rootObjects().first()->findChild<QObject*>("rich");
                    if (o) {
                        QQuickItem *item = qobject_cast<QQuickItem*>(o);
                        if (item) {
                            qDebug() << "got item";
                            QTextEdit *rich = qobject_cast<QTextEdit*>(o);  //this does not work
                            if (rich) {
                                qDebug() << "got rich";
                            }
                        }
                
                J Offline
                J Offline
                jalomic
                wrote on last edited by
                #7

                @VStevenP said:

                QQuickItem

                QML text edit it is not just QTextEdit . It is QQuickTextEdit class

                VStevenPV p3c0P 2 Replies Last reply
                0
                • J jalomic

                  @VStevenP said:

                  QQuickItem

                  QML text edit it is not just QTextEdit . It is QQuickTextEdit class

                  VStevenPV Offline
                  VStevenPV Offline
                  VStevenP
                  wrote on last edited by
                  #8

                  @jalomic Thanks for the clarification. That's good to know in case I ever want to look at the code.

                  @whitecastleroad Earlier in the thread I had mentioned about using the QML_DECLARE_TYPE macro. I did some more reading, and I learned that macro is vestigial and no longer needed/used. If you use Q_OBJECT macro in your class and simply use qmlRegisterType() in your main.cpp as documented in the Qt online doc, that is enough to make your class available to QML.

                  1 Reply Last reply
                  0
                  • J jalomic

                    @VStevenP said:

                    QQuickItem

                    QML text edit it is not just QTextEdit . It is QQuickTextEdit class

                    p3c0P Offline
                    p3c0P Offline
                    p3c0
                    Moderators
                    wrote on last edited by
                    #9

                    @jalomic But QQuickTextEdit is not public and hence can't be casted unless you include the private headers but which again is not recommended.

                    157

                    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