Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to adapt the touchscreen to a rotated application?

How to adapt the touchscreen to a rotated application?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
3 Posts 2 Posters 1.4k 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.
  • G Offline
    G Offline
    Grynium
    wrote on last edited by
    #1

    I'm implementing a Qt application on an embedded platform. The application relies on the eglfs platform plugin and uses as input a touch screen.

    The application is shown on screen with a counter clockwise rotation of -90°. The rotation is performed at GPU level, using a virtual frame buffer.

    How to adapt the touchscreen to the rotated app? Is it possible to perform the rotation of the touch points at application level? If yes, how?

    I've tried to set the QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS environment variable but without success. When the variable is set, e.g. "QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS=rotate=270", the touch screen is no longer recognized.

    Thanks in advance for your time

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stan.m
      wrote on last edited by stan.m
      #2

      Don't do it that way -- a royal pain in the arse regarding touch input.

      To solve your problem in QML, move all your content into a top-level Item, center and rotate it. This will rotate all the Item's children: MouseArea's, Text components, etc..

      Here is a component that rotates a QML UI:

      // ScreenRotator.qml -- rotates contents when isRotated set true
      
      import QtQuick 2.0
      
      Item {
          property bool isRotated: true
      
          anchors.centerIn: parent
          rotation: isRotated ? -90 : 0
          width: isRotated ? parent.height : parent.width
          height: isRotated ? parent.width : parent.height
          Component.onCompleted: if (isRotated) showFullScreen()
      }
      

      Here is an example of usage:

      // Demonstrates ScreenRotator component, rotating display 90 degrees
      
      import QtQuick 2.5
      import QtQuick.Window 2.2
      
      Window {
          width: 320; height: 240
          visible: true
      
          ScreenRotator {
              id: screenRotator
      
              isRotated: (Screen.width == 800)  // Target has 800x600 display
      
              Rectangle {  // Background changes color when click misses 'Quit' box
                  anchors.fill: parent
                  color: mouseArea.pressed ? 'orangered' : 'white'
      
                  MouseArea { id: mouseArea; anchors.fill: parent }
              }
              Text {  // Show the type of current platform and window dimensions
                  anchors.centerIn: parent
                  horizontalAlignment: Text.AlignHCenter
                  text: '%1\n(%2x%3)'
                        .arg((screenRotator.isRotated
                              ? qsTr('Embedded')
                              : qsTr('Workstation')))
                        .arg(parent.width)
                        .arg(parent.height)
              }
              Rectangle {
                  anchors { right: parent.right; bottom: parent.bottom }
                  width: label.width + label.height; height: 1.5*label.height
                  color: 'brown'
      
                  Text { id: label; text: qsTr('Quit'); color: 'white'; anchors.centerIn: parent }
                  MouseArea { anchors.fill: parent; onClicked: Qt.quit() }
              }
          }
      }
      
      G 1 Reply Last reply
      0
      • S stan.m

        Don't do it that way -- a royal pain in the arse regarding touch input.

        To solve your problem in QML, move all your content into a top-level Item, center and rotate it. This will rotate all the Item's children: MouseArea's, Text components, etc..

        Here is a component that rotates a QML UI:

        // ScreenRotator.qml -- rotates contents when isRotated set true
        
        import QtQuick 2.0
        
        Item {
            property bool isRotated: true
        
            anchors.centerIn: parent
            rotation: isRotated ? -90 : 0
            width: isRotated ? parent.height : parent.width
            height: isRotated ? parent.width : parent.height
            Component.onCompleted: if (isRotated) showFullScreen()
        }
        

        Here is an example of usage:

        // Demonstrates ScreenRotator component, rotating display 90 degrees
        
        import QtQuick 2.5
        import QtQuick.Window 2.2
        
        Window {
            width: 320; height: 240
            visible: true
        
            ScreenRotator {
                id: screenRotator
        
                isRotated: (Screen.width == 800)  // Target has 800x600 display
        
                Rectangle {  // Background changes color when click misses 'Quit' box
                    anchors.fill: parent
                    color: mouseArea.pressed ? 'orangered' : 'white'
        
                    MouseArea { id: mouseArea; anchors.fill: parent }
                }
                Text {  // Show the type of current platform and window dimensions
                    anchors.centerIn: parent
                    horizontalAlignment: Text.AlignHCenter
                    text: '%1\n(%2x%3)'
                          .arg((screenRotator.isRotated
                                ? qsTr('Embedded')
                                : qsTr('Workstation')))
                          .arg(parent.width)
                          .arg(parent.height)
                }
                Rectangle {
                    anchors { right: parent.right; bottom: parent.bottom }
                    width: label.width + label.height; height: 1.5*label.height
                    color: 'brown'
        
                    Text { id: label; text: qsTr('Quit'); color: 'white'; anchors.centerIn: parent }
                    MouseArea { anchors.fill: parent; onClicked: Qt.quit() }
                }
            }
        }
        
        G Offline
        G Offline
        Grynium
        wrote on last edited by
        #3

        @stan.m thank you very much for your time. Unfortunately the solution you have proposed is not suitable for my needs. The rotation must be performed at GPU level, it's not possible to make it at application level.

        The question remains unaswered

        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