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. The way to display a window using "virtualGeometry" of Qscreen in Qt Widget
Forum Updated to NodeBB v4.3 + New Features

The way to display a window using "virtualGeometry" of Qscreen in Qt Widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 652 Views 1 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.
  • M Offline
    M Offline
    morita
    wrote on last edited by
    #1

    Hello. I have three screens. And I try to display a window using virtualGeometry of QScreen in Qt Widget.

    But I can not correctly display a window .Because a widnow is displayed on only a primary screen.

    Do you know how to solve it ?

    For example, in case of QML , If I use the following code , I can display a window on a proper screen.

    /////////////////////////////////////////////////
    Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    screen:Qt.application.screens[0] //screen number
    x:screen.virtualX
    y:screen.virtualY
    }
    /////////////////////////////////////////////////

    In accordance with the above way, I tried to display a window using "virtualGeometry" of Qscreen in Qt Widget.

    /////////////////////////////////////////////////
    ChartDesign::ChartDesign(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::ChartDesign)
    {
    ui->setupUi(this);

    //Set Top-Level Window
    QWidget::setWindowFlag(Qt::FramelessWindowHint);
    QWidget::setWindowFlag(Qt::WindowStaysOnTopHint);
    
    //Set window Color
    QPalette Pal(palette());
    Pal.setColor(QPalette::Background, "#444343");
    this->setAutoFillBackground(true);
    this->setPalette(Pal);
    
    QScreen *screen = QGuiApplication::screens()[1]; //→Screen numbers 0,1,2
    QRect desktop = screen->virtualGeometry();
    this->setGeometry(desktop);
    

    // this->move(screen->geometry().x(), screen->geometry().y());
    this->move(screen->virtualGeometry().x(), screen->virtualGeometry().y());

    qDebug() << "screen->availableVirtualGeometry().x():" << screen->availableVirtualGeometry().x();
    this->resize(800, 400);
    ui->frame->setStyleSheet("background-color:green;");
    this->show();
    

    }
    ///////////////////////////////////

    If I use geometry of QScreen , I can display it .

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      virtualGeometry normally returns the extended desktop
      like 0,0-5770,1080
      (for 3 screens)

      So i wonder if you want to use screen->availableGeometry() instead ?
      or maybe screen->availableSize()

      or you can try like ( include #include <QWindow> )
      which have worked fine for me on windows.

      QWidget * widget = new QWidget();
      widget->show();
      widget->windowHandle()->setScreen(qApp->screens()[1]);
      widget->showFullScreen();

      1 Reply Last reply
      0
      • M Offline
        M Offline
        morita
        wrote on last edited by
        #3

        @mrjj
        Thank you for replying . I may misunderstand virtualGeometry().

        I guess a same way to get x or y coordinate using screen and screen.virtualX from screen in QML , is the way to use screen->geometry().x() in Widget.

        Is it correct ?? Because I thought the virtualGeometry() in Widget is same as the screen,virtualX in QML...

        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