0

I am using Embedded QT 4.8. Widgets are based on QGraphicsView and QGraphicsWidget. Need to control two displays.

So far I was able to find suggestions how to control two displays using QDesktopWidget, which is QWidget. I assume there must be a way to control two screens, using two frame buffers, via QGraphicsWidget.

Can somebody please give me a reference with examples how to paint on two screens using QGraphicsView and QGraphicsWidget, and two frame buffers?

Thanks, Dusan Mudric.

1 Answers1

0

Try this. I dont have 2 screens so I cant test

int main(int argc, char *argv[])
{
  QGuiApplication app(argc, argv);
  QQuickView view1(QUrl(QStringLiteral("qrc:/Screen1.qml")));
  qDebug() << app.screens().length();

  QScreen* screen1 = app.screens().at(0);
  QScreen* screen2 = app.screens().at(1);

  view1.setGeometry(0,0,200,200);
  view1.setScreen(screen1);
  view1.show();

  QQuickView view2(QUrl(QStringLiteral("qrc:/Screen2.qml")));
  view2.setGeometry(0,0,200,200);
  view2.setScreen(screen2);
  view2.show();

  return app.exec();
}

See unrelated but similar question Multiple Screens with Qt

Dr Deo
  • 4,650
  • 11
  • 43
  • 73
  • Thanks. I saw that link. My QT does not have QQuickView. The code base is huge and based on QGraphicsView and QGraphicsWidget. i need a way to display QGraphicsScene, or QGraphicsView, or its rectangle, via fb0 or fb1. – user1521589 Jan 09 '19 at 15:18
  • The method `setScreen(screen)` is also found in QWindow. Am guessing your QGraphicsView is inside a QWindow or a QDialog. Try calling `setScreen` on that `http://doc.qt.io/qt-5/qwindow.html#setScreen` – Dr Deo Jan 09 '19 at 18:00
  • The QT application uses QGraphicsScene rectangle to visualize QGraphicsView on the first screen
     QGraphicsScene* pScene = new QGraphicsScene(); QGraphicsView* pView =  new QGraphicsView(pScene); pView->showFullScreen();  QGraphicsWidget images are painted in the rectangle set by setGeometry, using QPainter.
    – user1521589 Jan 09 '19 at 21:27
  • `QWindow * window=pView->windowHandle()` to get associated `QWindow`. Then `QScreen* screen1 = app.screens().at(0); window->setGeometry(0,0,200,200);window->setScreen(screen1);` The QWidget->windowHandle() introduced in qt5. Your QGraphicsView propably needs to be a top level widget with no parent. Are you making a game or what? – Dr Deo Jan 09 '19 at 23:17
  • I am using QT 4.8.7 and it does not have windowHandle(). Should it be possible to define a bigger QGraphicsScene rectangle, where the second screen is on the right, using pScene->setSceneRect(), where the rectangle size is {screen_1X+screen_2X, max(screen_1Y, screen_2Y)}? When adding skins for the second screen, can QT just position them using screen_1X offset? – user1521589 Jan 10 '19 at 14:57
  • Can this be done: QDesktopWidget *desktop= QApplication::desktop(); (NOTE: all widgets are still QGraphicsWidget) if (screen1) desktop->screenGeometry(0); else if (screen2) desktop->screenGeometry(1); Each image is painted independently, providing the image rectangle {x,y,w,h}: pPainter_screen1->drawPixmap(x+screen0_x, y, w, h, &pm, sx+screen0_x, sy, sw, sh); The painter object comes from the QGraphicsWidget ‘paint’ callback function: void QGraphicsWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); – user1521589 Jan 10 '19 at 18:22