Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. dual screen Qml, QWidget application
Forum Updated to NodeBB v4.3 + New Features

dual screen Qml, QWidget application

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 833 Views 2 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
    Anas_Deshmukh
    wrote on last edited by
    #1

    hi everyone,

    requirement is to run multi-display application using qt4.8.6 on ubuntu14.04.

    on my primary display i am using qml,
    on secondary diaplay i am running qwidget (by adjusting its x and y points).

    i need help on two doubts i am having right now.

    1. is my approach running secondary display is correct or not? can i evoke one more qml file from my main application. any more correct way to do same?
        QmlApplicationViewer viewer;
        viewer.setMainQmlFile(QLatin1String("qml/newDisplay/main.qml"));
    
    
    1. currently when i pressed "Alt+F4" or "crash" happens, my main application and primary qml will close properly but secondary display keep running.

    I figured out that "alt+f4" affect where i am having current focus. it surely close qml or qwidget only ONE at time.

    kindly help me to write correct demo code. :)

    /// secondaryDisplay.h /// 
    
    #ifndef SECONDARYDISPLAY_H
    #define SECONDARYDISPLAY_H
    #include <QtCore>
    #include <QDebug>
    #include<QWidget>
    #include <QLabel>
    #include<QGraphicsScene>
    #include <QGraphicsView>
    #include <QGraphicsPixmapItem>
    
    class secondaryDisplay: public QObject
    {
        Q_OBJECT
    public:
        secondaryDisplay();
    //    QWidget * displayWidg//et = new QWidget();
        QLabel * tariffLabel;
        QString tariffStringAmount;
        QLabel *labelTariffAmount;// =  new QLabel(displayWidget);//("Total Tariff :", displayWidget);
        QString greetingMsg;
    
    public :
        Q_INVOKABLE void showSecondaryDisplay();
    
    public Q_SLOTS:
    
        Q_INVOKABLE void setDisplayTariffAmount(QString amount);
        Q_INVOKABLE void setGreetingMsg();
    
    private:
    };
    #endif // SECONDARYDISPLAY_H
    
    
    /// secondarydisplay.cpp //
    
    
    #include "secondarydisplay.h"
    secondaryDisplay::secondaryDisplay()
    {
        this->tariffStringAmount="0";
    }
    
    void secondaryDisplay::setDisplayTariffAmount(QString amount)
    {
        qDebug() << "secondaryDisplay :: slot called..";
        this->labelTariffAmount->setText(amount);
    }
    
    void secondaryDisplay::setGreetingMsg()
    {
        this->greetingMsg="Welcome\nTo Secure Park.";
        qDebug() << "greetingMsg :  " << greetingMsg;
    }
    
    void secondaryDisplay::showSecondaryDisplay()
    {
        QWidget *displayWidget = new QWidget();
        displayWidget->move(QPoint(1366, 0)); /// x cord. shift for second display
    //    displayWidget->resize(400,250);
        displayWidget->setStyleSheet("background-color:white;");
        displayWidget->setWindowState(Qt::WindowFullScreen);
    
    
    /// image label
        QLabel *imageLabel = new QLabel(displayWidget);
        imageLabel->setGeometry(10, 10, 1000, 150);
    
     // set a scaled pixmap to a w x h window keeping its aspect ratio
    
        QPixmap logo("/home/user/bundle/secure.jpg");
    
        int w = imageLabel->width();
        int h = imageLabel->height();
        imageLabel->setPixmap(logo.scaled(w,h));
    
    ///Greeting label
    //    QLabel *greetinLabel = new QLabel(displayWidget);
    //    greetinLabel->setText(this->greetingMsg);
    //    greetinLabel->setGeometry(10, 10, 1000, 150);
    //    greetinLabel->setStyleSheet("font: 40pt;");
    
    ///tariff label
        QLabel *labelTariffText =  new QLabel(displayWidget);//("Total Tariff :", displayWidget);
        labelTariffText->setText("TOTAL :");
    //    label.setText("welcome");
        labelTariffText->setGeometry(10, 585, 400, 150);
        labelTariffText->setStyleSheet("font: 70pt;");
        labelTariffText->setAlignment(Qt::AlignLeft);
    
    ///tariff amount label
        labelTariffAmount =  new QLabel(displayWidget);//("Total Tariff :", displayWidget);
        labelTariffAmount->setText(this->tariffStringAmount);
    //    label.setText("welcome");
        labelTariffAmount->setGeometry(380, 580, 600, 200);
    //    labelTariffAmount->setStyleSheet("background-color:white;");
        labelTariffAmount->setStyleSheet("font: 80pt;");
        labelTariffAmount->setAlignment(Qt::AlignRight);
    
        displayWidget->show();
    }
    
    // main.cpp ///
    
    
    #include <QApplication>
    #include "qmlapplicationviewer.h"
    
    #include "secondarydisplay.h"
    #include <QSound>
    
    #include <QtMultimedia>
    #include <QAudio>
    
    Q_DECL_EXPORT int main(int argc, char *argv[])
    {
        QScopedPointer<QApplication> app(createApplication(argc, argv));
    
        QmlApplicationViewer viewer;
        viewer.addImportPath(QLatin1String("modules"));
        viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
        viewer.setMainQmlFile(QLatin1String("qml/newDisplay/main.qml"));
        viewer.showExpanded();
    
    
        secondaryDisplay secondaryDisplayObj;
        secondaryDisplayObj.setGreetingMsg();
        secondaryDisplayObj.showSecondaryDisplay();
    
        return app->exec();
    }
    
    
    
    J.HilkJ 1 Reply Last reply
    0
    • K Offline
      K Offline
      karlheinzreichel
      wrote on last edited by
      #2

      @Anas_Deshmukh said in dual screen Qml, QWidget application:

      currently when i pressed "Alt+F4" or "crash" happens, my main application and primary qml will close properly but secondary display keep running.

      I think that is not possible, as you open your secondary display with widget->show().
      So leaving the message loop in main application will close also your secondary display.

      I assume your application will not be terminating after Alt+F4.

      1 Reply Last reply
      1
      • A Anas_Deshmukh

        hi everyone,

        requirement is to run multi-display application using qt4.8.6 on ubuntu14.04.

        on my primary display i am using qml,
        on secondary diaplay i am running qwidget (by adjusting its x and y points).

        i need help on two doubts i am having right now.

        1. is my approach running secondary display is correct or not? can i evoke one more qml file from my main application. any more correct way to do same?
            QmlApplicationViewer viewer;
            viewer.setMainQmlFile(QLatin1String("qml/newDisplay/main.qml"));
        
        
        1. currently when i pressed "Alt+F4" or "crash" happens, my main application and primary qml will close properly but secondary display keep running.

        I figured out that "alt+f4" affect where i am having current focus. it surely close qml or qwidget only ONE at time.

        kindly help me to write correct demo code. :)

        /// secondaryDisplay.h /// 
        
        #ifndef SECONDARYDISPLAY_H
        #define SECONDARYDISPLAY_H
        #include <QtCore>
        #include <QDebug>
        #include<QWidget>
        #include <QLabel>
        #include<QGraphicsScene>
        #include <QGraphicsView>
        #include <QGraphicsPixmapItem>
        
        class secondaryDisplay: public QObject
        {
            Q_OBJECT
        public:
            secondaryDisplay();
        //    QWidget * displayWidg//et = new QWidget();
            QLabel * tariffLabel;
            QString tariffStringAmount;
            QLabel *labelTariffAmount;// =  new QLabel(displayWidget);//("Total Tariff :", displayWidget);
            QString greetingMsg;
        
        public :
            Q_INVOKABLE void showSecondaryDisplay();
        
        public Q_SLOTS:
        
            Q_INVOKABLE void setDisplayTariffAmount(QString amount);
            Q_INVOKABLE void setGreetingMsg();
        
        private:
        };
        #endif // SECONDARYDISPLAY_H
        
        
        /// secondarydisplay.cpp //
        
        
        #include "secondarydisplay.h"
        secondaryDisplay::secondaryDisplay()
        {
            this->tariffStringAmount="0";
        }
        
        void secondaryDisplay::setDisplayTariffAmount(QString amount)
        {
            qDebug() << "secondaryDisplay :: slot called..";
            this->labelTariffAmount->setText(amount);
        }
        
        void secondaryDisplay::setGreetingMsg()
        {
            this->greetingMsg="Welcome\nTo Secure Park.";
            qDebug() << "greetingMsg :  " << greetingMsg;
        }
        
        void secondaryDisplay::showSecondaryDisplay()
        {
            QWidget *displayWidget = new QWidget();
            displayWidget->move(QPoint(1366, 0)); /// x cord. shift for second display
        //    displayWidget->resize(400,250);
            displayWidget->setStyleSheet("background-color:white;");
            displayWidget->setWindowState(Qt::WindowFullScreen);
        
        
        /// image label
            QLabel *imageLabel = new QLabel(displayWidget);
            imageLabel->setGeometry(10, 10, 1000, 150);
        
         // set a scaled pixmap to a w x h window keeping its aspect ratio
        
            QPixmap logo("/home/user/bundle/secure.jpg");
        
            int w = imageLabel->width();
            int h = imageLabel->height();
            imageLabel->setPixmap(logo.scaled(w,h));
        
        ///Greeting label
        //    QLabel *greetinLabel = new QLabel(displayWidget);
        //    greetinLabel->setText(this->greetingMsg);
        //    greetinLabel->setGeometry(10, 10, 1000, 150);
        //    greetinLabel->setStyleSheet("font: 40pt;");
        
        ///tariff label
            QLabel *labelTariffText =  new QLabel(displayWidget);//("Total Tariff :", displayWidget);
            labelTariffText->setText("TOTAL :");
        //    label.setText("welcome");
            labelTariffText->setGeometry(10, 585, 400, 150);
            labelTariffText->setStyleSheet("font: 70pt;");
            labelTariffText->setAlignment(Qt::AlignLeft);
        
        ///tariff amount label
            labelTariffAmount =  new QLabel(displayWidget);//("Total Tariff :", displayWidget);
            labelTariffAmount->setText(this->tariffStringAmount);
        //    label.setText("welcome");
            labelTariffAmount->setGeometry(380, 580, 600, 200);
        //    labelTariffAmount->setStyleSheet("background-color:white;");
            labelTariffAmount->setStyleSheet("font: 80pt;");
            labelTariffAmount->setAlignment(Qt::AlignRight);
        
            displayWidget->show();
        }
        
        // main.cpp ///
        
        
        #include <QApplication>
        #include "qmlapplicationviewer.h"
        
        #include "secondarydisplay.h"
        #include <QSound>
        
        #include <QtMultimedia>
        #include <QAudio>
        
        Q_DECL_EXPORT int main(int argc, char *argv[])
        {
            QScopedPointer<QApplication> app(createApplication(argc, argv));
        
            QmlApplicationViewer viewer;
            viewer.addImportPath(QLatin1String("modules"));
            viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
            viewer.setMainQmlFile(QLatin1String("qml/newDisplay/main.qml"));
            viewer.showExpanded();
        
        
            secondaryDisplay secondaryDisplayObj;
            secondaryDisplayObj.setGreetingMsg();
            secondaryDisplayObj.showSecondaryDisplay();
        
            return app->exec();
        }
        
        
        
        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @Anas_Deshmukh

        You''ll have to get into your destructor functions, of the qml file and the QWidget, and call QApplication::quit manually.

        //QML
        Component.onDestruction: {
                Qt.quit()
            }
        
        //QWidgets
        MainWindow::~Mainwindow()
        {
             delete ui;
             QApplication::quit();
        }
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @J-Hilk It should happen automatically unless the quitOnLastWindowClosed property has been changed.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          J.HilkJ 1 Reply Last reply
          1
          • SGaistS SGaist

            @J-Hilk It should happen automatically unless the quitOnLastWindowClosed property has been changed.

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @SGaist
            Maybe I missread the question, but I thought the goal was it to close the whole application when either one one of the Windows (primary or secondary screen) is closed

            currently when i pressed "Alt+F4" or "crash" happens, my main application and primary qml will close properly but secondary display keep running.

            Target: alt+F4 -> close whole app

            You're right however, that my post doesn't quite target the situation.
            The Qt.Quit() should be in a Shortcut sequence and the widget should have an event filter listening for the alt+f4 key combo.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Anas_Deshmukh
              wrote on last edited by
              #6

              Hi everyone,

              i am sorry for late reply. At the moment i am using 'QApplication::destroyed()' signal to close my extra widget.
              some how its working for me, but i am still doubtful in terms of standard coding.

              thank you for your help. :)

              // main.cpp
              
              Q_DECL_EXPORT int main(int argc, char *argv[])
              {
                  QScopedPointer<QApplication> app(createApplication(argc, argv));
              ...
              ...
              ...
                  secondaryDisplay secondaryDisplayObj ;//= new secondaryDisplay;
                  viewer.rootContext()->setContextProperty("secondaryDisplayObj",&secondaryDisplayObj); /// qml acess
                  secondaryDisplayObj.showSecondaryDisplay(); /// initiate my widget 
                  QObject::connect(app.data(),SIGNAL(destroyed()), &secondaryDisplayObj, SLOT(deletSecondaryDisplay()));
              
              // deletSecondaryDisplay :: my customised slot
              
              }
              
              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