dual screen Qml, QWidget application
-
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.
- 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"));
- 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(); }
-
@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.
-
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.
- 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"));
- 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(); }
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(); }
-
@J-Hilk It should happen automatically unless the quitOnLastWindowClosed property has been changed.
-
@J-Hilk It should happen automatically unless the quitOnLastWindowClosed property has been changed.
@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 closedcurrently 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. -
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 }