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. #ifdef MAC / Win / Linux in QML

#ifdef MAC / Win / Linux in QML

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 5 Posters 14.0k 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.
  • B Offline
    B Offline
    bunjee
    wrote on last edited by
    #1

    Dear Trolls,

    Is there a way to encapsulate platform specific code in QML like so:

    @
    Rectangle {
    mac {
    color: "#fff";
    }
    }@

    Thanks.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

      There are not only trolls here :)
      AFAIK it is impossible. But you can set context property with current platform (get it from ifdefs in c++) and work with it.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alexander
        wrote on last edited by
        #3

        But you can do separate QML files and load its in cpp code with "#ifdef MAC / Win / Linux in QML"

        1 Reply Last reply
        0
        • B Offline
          B Offline
          blam
          wrote on last edited by
          #4

          There is no built-in support for this in QML. As others pointed out, you can implement it in C++ if necessary.

          If you are trying to style the look of a component, you may be interested in http://developer.qt.nokia.com/wiki/QmlStyling.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bunjee
            wrote on last edited by
            #5

            Thanks Guys !

            Here is how I did it:

            @Rectangle {
            width:
            {
            if (wApplication.osMac) return imageBox.width + 1;
            else return imageBox.width;
            }
            }@

            wApplication is my context object property.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DenisKormalev
              wrote on last edited by
              #6

              bunjee, maybe be better will be to write
              @
              Rectangle {
              width: imageBox.width + (wApplication.osMac?1:0)
              }
              @

              1 Reply Last reply
              0
              • B Offline
                B Offline
                bunjee
                wrote on last edited by
                #7

                Thanks !

                Shorter but harder to read in my opinion.

                I'll think about it :-).

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  phyatt
                  wrote on last edited by
                  #8

                  I think the solution here is much more elegant.

                  http://qt-project.org/forums/viewthread/5862

                  @if (Qt.platform.os === "linux" || Qt.platform.os === "windows" || Qt.platform.os === "osx" || Qt.platform.os === "unix") {
                  //..
                  }@

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    phyatt
                    wrote on last edited by
                    #9

                    I think the solution here is much more elegant.

                    http://qt-project.org/forums/viewthread/5862

                    @if (Qt.platform.os === "linux" || Qt.platform.os === "windows" || Qt.platform.os === "osx" || Qt.platform.os === "unix") {
                    //..
                    }@

                    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