What is different in between laptop main screen and external connected screen?



  • I am getting different result for same coding in Qt 5.12.3

    Able to set widget parameter on main screen (Qt is running on main screen).
    0_1559843854726_main Screen.PNG

    Not set widget parameter on Sub screen (Qt is running on connected Screen).
    0_1559843930491_SubScreen.PNG

    Project Structure:
    0_1559844449034_51f885a8-a319-48fe-8b5e-f18839e404bb-image.png

    .pro file

    #-------------------------------------------------
    #
    # Project created by QtCreator 2019-05-29T12:19:35
    #
    #-------------------------------------------------
    
    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = ReplicaOfProject
    TEMPLATE = app
    
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which has been marked as deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    CONFIG += c++11
    
    SOURCES += \
            Mainwindow.cpp \
            MainwindowUI.cpp \
            main.cpp
    
    HEADERS += \
        Mainwindow.h \
        MainwindowUI.h
    RESOURCES += \
        gui.qrc
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    

    main.cpp

    #include "Mainwindow.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        return a.exec();
    }
    
    

    Mainwidnow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include "qfile.h"
    #include "qapplication.h"
    #include "qdesktopwidget.h"
    
    class MainWindowUI;
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
    private:
        MainWindowUI *ui;
    
        void ApplyStyle();
    };
    
    #endif // MAINWINDOW_H
    
    

    Mainwindow.cpp

    #include "Mainwindow.h"
    #include "MainwindowUI.h"
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent),ui(new MainWindowUI(this))
    {
        ui->CreateUI();
        ApplyStyle();
    }
    
    MainWindow::~MainWindow()
    {
    
    }
    
    void MainWindow::ApplyStyle() {
    
        QFile f(":/GUI/GUI.css");
        if (!f.open(QIODevice::ReadOnly))
            return;
    
        QString newStyleSheet = f.readAll();
    
        qobject_cast<QApplication *>(QApplication::instance())->setStyleSheet(newStyleSheet);
    
        f.close();
    }
    
    

    MainwindowUI.h

    #ifndef MAINWINDOWUI_H
    #define MAINWINDOWUI_H
    #include "Mainwindow.h"
    
    class MainWindowUI : public QObject
    {
        Q_OBJECT
    public:
        MainWindowUI(MainWindow *Parent);
        void CreateUI();
        void CraeteCentralWidget();
    
    
    signals:
    
    public slots:
    
    private:
        MainWindow *m_mainWidnow;
    };
    
    #endif // MAINWINDOWUI_H
    
    

    MainwidnowUI.cpp

    #include "MainwindowUI.h"
    
    MainWindowUI::MainWindowUI(MainWindow *parent) : m_mainWidnow(parent)
    {
    
    }
    
    
    void MainWindowUI::CreateUI(){
        CraeteCentralWidget();
    }
    void MainWindowUI::CraeteCentralWidget(){
    
    }
    
    

    GUI.css

    QMainWindow {
            min-width: 1366px;
            min-height: 768px;
    }
    
    

    What is wrong with my code? Why it is giving different result on two screen main screen and connected sunscreen?


  • Lifetime Qt Champion

    Hi,

    What are exactly these two screens ?
    What are their definitions ?
    Out of curiosity, why set the size of your widget in a style sheet ?



  • @SGaist said in What is different in between laptop main screen and external connected screen?:

    What are exactly these two screens ?

    I am using my laptop. another external monitor is connected to Laptop. If Qt is running on Laptop screen then it is perfectly fine, it is set widget parameter. If Qt is running on monitor then it not set the parameter meter of widget.

    @SGaist said in What is different in between laptop main screen and external connected screen?:

    Out of curiosity, why set the size of your widget in a style sheet ?

    I am setting the widget size from GUI.css style sheet because if screen size is change then I am changing widget minimum height and width. one of function is doing everything in my actual project.

    I have actual problem is warning due to Update. In one of my project I was using Qt 5.6.3. and I update the Qt version 5.12.3. I am getting this warning QWindowsWindow::setGeometry: Unable to set geometry 1366x768+2196+129 on QWidgetWindow/'mainUIWindow'. Resulting geometry: 1368x776+2196+129 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 1366x768, maximum size: 16777215x16777215).. So that I time trying to find of warning place by creating duplicate of Project.

    Warning is generated whenever actual project is running on external monitor.


  • Lifetime Qt Champion

    Again: what kind of monitor is that ? What is its resolution ?
    What graphics card are you using ?

    If you want your widget to cover the whole screen, why not use QWidget::showMaximized ?



  • @SGaist said in What is different in between laptop main screen and external connected screen?:

    Again: what kind of monitor is that ? What is its resolution ?
    What graphics card are you using ?

    0_1559857072042_7d013b2a-5c42-4436-96f7-36ac2285fb3f-image.png ![0_1559856657804_26460070-fe65-4754-9462-d37e971b7475-image.png](Uploading 100%)

    @SGaist said in What is different in between laptop main screen and external connected screen?:

    If you want your widget to cover the whole screen, why not use QWidget::showMaximized ?

    I am trying to limit the minimum sized.

    I changed QWidget::show to QWidget::showMaximized. It is set minimum size of Qmainwindow. But it is still generate the warning.
    setGeometry: Unable to set geometry 1366x768+2196+129 on QWidgetWindow/'MainWindowClassWindow'. Resulting geometry: 1368x776+2196+129 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 1366x768, maximum size: 16777215x16777215).

    To remove the warning I tried below code, but nothing is change.

    #include "Mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
    {
        ApplyStyle();
    }
    
    MainWindow::~MainWindow()
    {
    
    }
    
    void MainWindow::ApplyStyle() {
    
        this->setMinimumWidth(1366);
        this->setMinimumHeight(768);
    
        //QFile f(":/GUI/GUI.css");
        //if (!f.open(QIODevice::ReadOnly))
            //return;
    
        //QString newStyleSheet = f.readAll();
    
        //qobject_cast<QApplication *>(QApplication::instance())->setStyleSheet(newStyleSheet);
    
        //f.close();
    
    }
    

    warning is generate if application start on external monitor.
    any suggestion to avoid warning?

    Thank you,
    Yash



  • got solution.

    before using the minimum size function set the windowstate Qt::WindowFullScreen. In my case I used line this->setWindowState(Qt::WindowFullScreen); before this->setMinimumWidth(1366); this->setMinimumHeight(768);.