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 to push a button on a bottom of a QWidget window from a overlayed QML window ?
Forum Update on Monday, May 27th 2025

How to push a button on a bottom of a QWidget window from a overlayed QML window ?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 295 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.
  • M Offline
    M Offline
    morita
    wrote on last edited by
    #1

    Hello.

    How do you push a button on a bottom of a QWidget window from a overlayed QML window ? I have two windows in my project based on Widget. One is a QWidget Window and the other is a QML window. I overlay the QML window on the QWidget window. I mean a z-position of the QML window is higher than a z-position of QWidget window. There is a button on the QWidget window. And the QML Window color is transparent.
    As we can see the button, we may be able to push the button on the QML Window.
    But I don't know how to push the button. I tried to use some options like "flags:WindowTransparentForInput".But I couldn't push the button.

    The following is my code.

    code_text

    main.qml 
    ・・・・
    import QmlChart 1.0
    Window {
        property int iDefineScreenNo:0
        id:window
        x:screen.virtualX
        y:screen.virtualY
        width:1368
        height:912
        visible: true
        title: qsTr("QML Window")
        color: "transparent"
        Rectangle {
            anchors.fill: parent
            border.color: "#14191D"
            border.width: 5
            color: "transparent"
        }
        //flags: Qt.FramelessWindowHint //Qt.WindowTransparentForInput
        //flags: Qt.WA_TranslucentBackground
        screen:Qt.application.screens[iDefineScreenNo]
    
        QmlChart{} →A connection class between the main.qml and the Chart class
    }
    
    /////////////////////////////////////////
    main.cpp
    ・・・・
    #include "widget/qmlchart.h"
    int main(int argc, char *argv[])
    {
    
    	qmlRegisterType<QmlChart>("QmlChart", 1, 0, "QmlChart");
    	QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    
    	QApplication app(argc, argv);
    
    	・・・・・
    }
    
    ////////////////////////////////////////////////////////
    qmlchart.h/qmlchart.cpp
    #include <QObject>
    #include "chart.h"
    
    class QmlChart : public QObject
    {
    public:
    	QmlChart(QObject *parent = nullptr);
    
    private:
    	Chart m_chart; /
    };
    
    //
    QmlChart::QmlChart(QObject *parent) : QObject(parent)
    {
    	//Display the chart
    	m_chart.setVisible(true);
    }
    
    /////////////////////////////////////////////////////////////
    chart.h/chart.cpp
    namespace Ui {
    class Chart;
    }
    
    class Chart : public QWidget
    {
    	Q_OBJECT
    
    public:
    	explicit Chart(QWidget *parent = nullptr);
    	~Chart();
    
    public slots:
    	void buttonClicked();
    
    private:
    	Ui::Chart *ui;
    	QScreen*         screen;
    	QPushButton *m_button;
    };
    
    //
    Chart::Chart(QWidget *parent) :
    	QWidget(parent),
    	ui(new Ui::Chart)
    {
    	ui->setupUi(this);
    	this->show();
    
    ・・・・・・
    	// signal and slot
    	connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(buttonClicked()));
    
    ・・・・
    }
    raven-worxR 1 Reply Last reply
    0
    • M morita

      Hello.

      How do you push a button on a bottom of a QWidget window from a overlayed QML window ? I have two windows in my project based on Widget. One is a QWidget Window and the other is a QML window. I overlay the QML window on the QWidget window. I mean a z-position of the QML window is higher than a z-position of QWidget window. There is a button on the QWidget window. And the QML Window color is transparent.
      As we can see the button, we may be able to push the button on the QML Window.
      But I don't know how to push the button. I tried to use some options like "flags:WindowTransparentForInput".But I couldn't push the button.

      The following is my code.

      code_text

      main.qml 
      ・・・・
      import QmlChart 1.0
      Window {
          property int iDefineScreenNo:0
          id:window
          x:screen.virtualX
          y:screen.virtualY
          width:1368
          height:912
          visible: true
          title: qsTr("QML Window")
          color: "transparent"
          Rectangle {
              anchors.fill: parent
              border.color: "#14191D"
              border.width: 5
              color: "transparent"
          }
          //flags: Qt.FramelessWindowHint //Qt.WindowTransparentForInput
          //flags: Qt.WA_TranslucentBackground
          screen:Qt.application.screens[iDefineScreenNo]
      
          QmlChart{} →A connection class between the main.qml and the Chart class
      }
      
      /////////////////////////////////////////
      main.cpp
      ・・・・
      #include "widget/qmlchart.h"
      int main(int argc, char *argv[])
      {
      
      	qmlRegisterType<QmlChart>("QmlChart", 1, 0, "QmlChart");
      	QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      
      	QApplication app(argc, argv);
      
      	・・・・・
      }
      
      ////////////////////////////////////////////////////////
      qmlchart.h/qmlchart.cpp
      #include <QObject>
      #include "chart.h"
      
      class QmlChart : public QObject
      {
      public:
      	QmlChart(QObject *parent = nullptr);
      
      private:
      	Chart m_chart; /
      };
      
      //
      QmlChart::QmlChart(QObject *parent) : QObject(parent)
      {
      	//Display the chart
      	m_chart.setVisible(true);
      }
      
      /////////////////////////////////////////////////////////////
      chart.h/chart.cpp
      namespace Ui {
      class Chart;
      }
      
      class Chart : public QWidget
      {
      	Q_OBJECT
      
      public:
      	explicit Chart(QWidget *parent = nullptr);
      	~Chart();
      
      public slots:
      	void buttonClicked();
      
      private:
      	Ui::Chart *ui;
      	QScreen*         screen;
      	QPushButton *m_button;
      };
      
      //
      Chart::Chart(QWidget *parent) :
      	QWidget(parent),
      	ui(new Ui::Chart)
      {
      	ui->setupUi(this);
      	this->show();
      
      ・・・・・・
      	// signal and slot
      	connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(buttonClicked()));
      
      ・・・・
      }
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @morita said in How to push a button on a bottom of a QWidget window from a overlayed QML window ?:

      I tried to use some options like "flags:WindowTransparentForInput".But I couldn't push the button.

      the operating system send input events to the active/focused widget, but never passes them on to the underlaying window if the event is not consumed.
      Pretty clear why not when thinking of the reason not to do so.

      Since you want to send an event to a different window in your application you can bypass the OS and simply send a generated event yourself directly to the window widget.

      QPoint screenPos(...,....);
      if( QWidget *receiver = windowWidget->childAt(windowWidget->mapFromGlobal(screenPos)) )
      {
          QPoint localPos = receiver->mapFromGlobal(screenPos);
          // press event
          QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress, localPos, screenPos, Qt::LeftButton, Qt::LeftButton,  Qt::NoModifier);
          QCoreApplication::postEvent(receiver, event);
         // release event
          QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonRelease, localPos, screenPos, Qt::LeftButton, Qt::LeftButton,  Qt::NoModifier);
          QCoreApplication::postEvent(receiver, event);
      }
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      M 1 Reply Last reply
      1
      • raven-worxR raven-worx

        @morita said in How to push a button on a bottom of a QWidget window from a overlayed QML window ?:

        I tried to use some options like "flags:WindowTransparentForInput".But I couldn't push the button.

        the operating system send input events to the active/focused widget, but never passes them on to the underlaying window if the event is not consumed.
        Pretty clear why not when thinking of the reason not to do so.

        Since you want to send an event to a different window in your application you can bypass the OS and simply send a generated event yourself directly to the window widget.

        QPoint screenPos(...,....);
        if( QWidget *receiver = windowWidget->childAt(windowWidget->mapFromGlobal(screenPos)) )
        {
            QPoint localPos = receiver->mapFromGlobal(screenPos);
            // press event
            QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress, localPos, screenPos, Qt::LeftButton, Qt::LeftButton,  Qt::NoModifier);
            QCoreApplication::postEvent(receiver, event);
           // release event
            QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonRelease, localPos, screenPos, Qt::LeftButton, Qt::LeftButton,  Qt::NoModifier);
            QCoreApplication::postEvent(receiver, event);
        }
        
        M Offline
        M Offline
        morita
        wrote on last edited by
        #3

        @raven-worx

        Thank you for replying.

        First of all, Do I have to code Your code in Chart Class ? Is it correct ? And are values of arguments in ScreenPos the signal values of cordinates by mouseEvent of QML Window?

        raven-worxR 1 Reply Last reply
        0
        • M morita

          @raven-worx

          Thank you for replying.

          First of all, Do I have to code Your code in Chart Class ? Is it correct ? And are values of arguments in ScreenPos the signal values of cordinates by mouseEvent of QML Window?

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @morita said in How to push a button on a bottom of a QWidget window from a overlayed QML window ?:

          First of all, Do I have to code Your code in Chart Class ? Is it correct ?

          You can put it into a custom QObject and add a invokable method which executes this code reuseable.

          And are values of arguments in ScreenPos the signal values of cordinates by mouseEvent of QML Window?

          use the items mapToGlobal() function to map it to screen coordinates.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          M 1 Reply Last reply
          0
          • raven-worxR raven-worx

            @morita said in How to push a button on a bottom of a QWidget window from a overlayed QML window ?:

            First of all, Do I have to code Your code in Chart Class ? Is it correct ?

            You can put it into a custom QObject and add a invokable method which executes this code reuseable.

            And are values of arguments in ScreenPos the signal values of cordinates by mouseEvent of QML Window?

            use the items mapToGlobal() function to map it to screen coordinates.

            M Offline
            M Offline
            morita
            wrote on last edited by
            #5

            @raven-worx

            Thank you so much . I finally make it .

            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