Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Configure resolution on Qt designer



  • Hello there!

    Right now i have an functional application with some threads and im using qt designer to create an UI which basicly contains one StackedWidged with three pages and some labels and buttons on each page.
    The problem i faced is that the RAM comsumption of my application increased a lot when i added de UI and adding widgets there is a moment the consumtion of my application increase much that is being killed by the system at the start of the application (it dont show nothing on the Monitor). I don't know if there is a way to reduce this RAM consumption, but i need to do something with this.

    Im running the application over RaspberryPi 3B (which have near to 1Gb RAM) and im connecting the raspberry PI throught HDMI to a monitor with 1920x1080 resolution and at the beggining on my desing i created the mainwindow with 1920x1080 size to have the same size in the editor.

    Once i found the RAM overconsumption problem I have been reading that "more resolution = more RAM consumption" so I tried decreasing the resolution to 1280x720 (throught "sudo raspi-config") and i made the same with my window size, but im having the same problem.

    My question is .... Its possible to reduce the RAM consumption reducing the resolution on the designer? If no ... What can I do to reduce this consumption?

    Thanks in advance.
    Pablo.


  • Lifetime Qt Champion

    Hi,

    What size are these ?
    What constraints do you have ?
    What kind of GUI are you building ?



  • @SGaist

    What size are these ?
    The size when i talk about the main window is the MainWindow QWidged Im using on the UI as the base of the interface, I mean, the <width> and <height> property of the widget MainWindow.

    What constraints do you have ?
    When i run my application i can see on top command that %MEM get values near to 90% and then muy application is being killed by the system, so i think the problem on my application is the RAM consumption.

    consumo.png

    If i run free -h command i get the following info:
    total used free shared buff/cache available
    Mem: 926M 48M 768M 1,2M 109M 827M
    Swap: 99M 47M 52M

    What kind of GUI are you building ?
    Im very new on GUI buildings so i dont know exactly what kinds of GUI exists ... i dont know if could help but following I show you the structure of the GUI.

    structure.JPG

    Thanks in advance,
    Pablo.


  • Lifetime Qt Champion

    I'm pretty sure those small amount of widgets is not the reason for the memory usage.


  • Lifetime Qt Champion

    I agree with @Christian-Ehrlicher, that small GUI does not add up with the amount of RAM used. What are you doing in your application ?
    Are you sure you don't have a memory leak ?



  • @Christian-Ehrlicher @SGaist thanks both for your answer ... but if I comment all the "UI related things" the memory usage fall to 3% ... maybe there is a problem on how im using this "UI related things", im going to try to explain you all the operations related.

    I have a thread class object (made by me and works correctly in much projects, we can asume there is not the problem) UIThread whos job is control the GUI, it have as private attributte a unique pointer to class MainWindow ( std::unique_ptr<MainWindow> pMainW).

    On UIThread constructor i reserve the memory to the MainWindows (pMainW = std::unique_ptr<MainWindow>(new MainWindow()); ).

    On UIThread body the only thing i do is check if there is change on the operation mode (which makes if i have to change the screen) and call show() methods created by me on MainWindow class which only makes "ui->StackedWidget->setCurrentIndex()" to the corresponding index and some setVisibile(false)/setVisibile(true) on some widgets.

    What do you think?Something you see is wrong?

    EDIT:
    I have been checking all the methods and objects and i find that the memory is being reserved inside the setupUi() method automatically generated by the MOC. I have also check if this method is being called more than one time but it dont happen, so i dont know why but the new calls inside the method are reserving all my memory...
    Im thinking about change the "new" call with static Qobjects but i dont know if it would works...
    Here is the code generated. ┬┐Something weird?

    /********************************************************************************
    ** Form generated from reading UI file 'mainwindow.ui'
    **
    ** Created by: Qt User Interface Compiler version 5.13.2
    **
    ** WARNING! All changes made in this file will be lost when recompiling UI file!
    ********************************************************************************/
    
    #ifndef UI_MAINWINDOW_H
    #define UI_MAINWINDOW_H
    
    #include <QtCore/QVariant>
    #include <QtWidgets/QApplication>
    #include <QtWidgets/QLabel>
    #include <QtWidgets/QPushButton>
    #include <QtWidgets/QStackedWidget>
    #include <QtWidgets/QWidget>
    
    #include <iostream>
    
    QT_BEGIN_NAMESPACE
    
    class Ui_MainWindow
    {
    public:
        QLabel *UOC_logo;
        QLabel *Date;
        QLabel *Time;
        QStackedWidget *StackedWidget;
        QWidget *ValidatePage;
        QLabel *ValText;
        QLabel *ValResult_logo;
        QLabel *ValName;
        QLabel *ValProfile;
        QPushButton *ValMaintButton;
        QWidget *MaintPage;
        QLabel *MaintTittle;
        QLabel *MaintText1;
        QPushButton *MaintValButton;
        QPushButton *MaintQueryButton;
        QPushButton *MaintBackButton;
        QLabel *MaintText2;
        QWidget *QueryPage;
        QLabel *QueryTittle;
        QLabel *QueryResult_logo;
        QLabel *QueryText;
        QLabel *QueryName;
        QLabel *QueryProfile;
        QLabel *QueryLastValInfo;
        QPushButton *QueryMaintButton;
    
        void setupUi(QWidget *MainWindow)
        {
            std::cout << "setupUi call" << std::endl;
    
            if (MainWindow->objectName().isEmpty())
                MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
            MainWindow->setEnabled(true);
            MainWindow->resize(1920, 1080);
            MainWindow->setAutoFillBackground(false);
            MainWindow->setStyleSheet(QString::fromUtf8("background : url(images/background.jpg)"));
            UOC_logo = new QLabel(MainWindow); std::cout << "UOC_logo size" << std::endl;
            UOC_logo->setObjectName(QString::fromUtf8("UOC_logo"));
            UOC_logo->setGeometry(QRect(50, 50, 241, 181));
            UOC_logo->setStyleSheet(QString::fromUtf8("background: url(images/uoc_logo.png)"));
            UOC_logo->setFrameShape(QFrame::WinPanel);
            Date = new QLabel(MainWindow);
            Date->setObjectName(QString::fromUtf8("Date"));
            Date->setGeometry(QRect(1460, 50, 421, 71));
            QFont font;
            font.setPointSize(36);
            font.setBold(true);
            font.setWeight(75);
            Date->setFont(font);
            Date->setStyleSheet(QString::fromUtf8(""));
            Date->setAlignment(Qt::AlignCenter);
            Time = new QLabel(MainWindow);
            Time->setObjectName(QString::fromUtf8("Time"));
            Time->setGeometry(QRect(1460, 120, 421, 71));
            Time->setFont(font);
            Time->setStyleSheet(QString::fromUtf8(""));
            Time->setAlignment(Qt::AlignCenter);
            StackedWidget = new QStackedWidget(MainWindow);
            StackedWidget->setObjectName(QString::fromUtf8("StackedWidget"));
            StackedWidget->setGeometry(QRect(0, 250, 1921, 831));
            ValidatePage = new QWidget();
            ValidatePage->setObjectName(QString::fromUtf8("ValidatePage"));
            ValidatePage->setEnabled(true);
            ValidatePage->setAutoFillBackground(false);
            ValidatePage->setStyleSheet(QString::fromUtf8("background : url(images/background.jpg)"));
            ValText = new QLabel(ValidatePage);
            ValText->setObjectName(QString::fromUtf8("ValText"));
            ValText->setGeometry(QRect(470, 300, 941, 101));
            QFont font1;
            font1.setPointSize(48);
            font1.setBold(false);
            font1.setWeight(50);
            ValText->setFont(font1);
            ValText->setAutoFillBackground(false);
            ValText->setStyleSheet(QString::fromUtf8(""));
            ValText->setAlignment(Qt::AlignCenter);
            ValResult_logo = new QLabel(ValidatePage);
            ValResult_logo->setObjectName(QString::fromUtf8("ValResult_logo"));
            ValResult_logo->setEnabled(true);
            ValResult_logo->setGeometry(QRect(840, 90, 231, 211));
            ValResult_logo->setStyleSheet(QString::fromUtf8("border: 0px"));
            ValResult_logo->setScaledContents(true);
            ValName = new QLabel(ValidatePage);
            ValName->setObjectName(QString::fromUtf8("ValName"));
            ValName->setGeometry(QRect(130, 500, 591, 101));
            QFont font2;
            font2.setPointSize(28);
            font2.setBold(false);
            font2.setWeight(50);
            ValName->setFont(font2);
            ValName->setAutoFillBackground(false);
            ValName->setStyleSheet(QString::fromUtf8(""));
            ValProfile = new QLabel(ValidatePage);
            ValProfile->setObjectName(QString::fromUtf8("ValProfile"));
            ValProfile->setGeometry(QRect(130, 590, 591, 101));
            ValProfile->setFont(font2);
            ValProfile->setAutoFillBackground(false);
            ValProfile->setStyleSheet(QString::fromUtf8(""));
            ValMaintButton = new QPushButton(ValidatePage);
            ValMaintButton->setObjectName(QString::fromUtf8("ValMaintButton"));
            ValMaintButton->setGeometry(QRect(20, 750, 61, 61));
            ValMaintButton->setIconSize(QSize(50, 50));
            StackedWidget->addWidget(ValidatePage);
            MaintPage = new QWidget();
            MaintPage->setObjectName(QString::fromUtf8("MaintPage"));
            MaintTittle = new QLabel(MaintPage);
            MaintTittle->setObjectName(QString::fromUtf8("MaintTittle"));
            MaintTittle->setGeometry(QRect(520, 0, 941, 101));
            MaintTittle->setFont(font1);
            MaintTittle->setAutoFillBackground(false);
            MaintTittle->setStyleSheet(QString::fromUtf8(""));
            MaintTittle->setAlignment(Qt::AlignCenter);
            MaintText1 = new QLabel(MaintPage);
            MaintText1->setObjectName(QString::fromUtf8("MaintText1"));
            MaintText1->setGeometry(QRect(130, 90, 651, 101));
            MaintText1->setFont(font2);
            MaintText1->setAutoFillBackground(false);
            MaintText1->setStyleSheet(QString::fromUtf8(""));
            MaintText1->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter);
            MaintValButton = new QPushButton(MaintPage);
            MaintValButton->setObjectName(QString::fromUtf8("MaintValButton"));
            MaintValButton->setGeometry(QRect(500, 180, 381, 121));
            QFont font3;
            font3.setPointSize(16);
            MaintValButton->setFont(font3);
            MaintValButton->setIconSize(QSize(50, 50));
            MaintQueryButton = new QPushButton(MaintPage);
            MaintQueryButton->setObjectName(QString::fromUtf8("MaintQueryButton"));
            MaintQueryButton->setGeometry(QRect(1010, 180, 381, 121));
            MaintQueryButton->setFont(font3);
            MaintQueryButton->setIconSize(QSize(50, 50));
            MaintBackButton = new QPushButton(MaintPage);
            MaintBackButton->setObjectName(QString::fromUtf8("MaintBackButton"));
            MaintBackButton->setGeometry(QRect(20, 750, 61, 61));
            MaintBackButton->setIconSize(QSize(50, 50));
            MaintText2 = new QLabel(MaintPage);
            MaintText2->setObjectName(QString::fromUtf8("MaintText2"));
            MaintText2->setGeometry(QRect(130, 340, 521, 101));
            MaintText2->setFont(font2);
            MaintText2->setAutoFillBackground(false);
            MaintText2->setStyleSheet(QString::fromUtf8(""));
            MaintText2->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter);
            StackedWidget->addWidget(MaintPage);
            QueryPage = new QWidget();
            QueryPage->setObjectName(QString::fromUtf8("QueryPage"));
            QueryTittle = new QLabel(QueryPage);
            QueryTittle->setObjectName(QString::fromUtf8("QueryTittle"));
            QueryTittle->setGeometry(QRect(40, 10, 471, 101));
            QueryTittle->setFont(font1);
            QueryTittle->setAutoFillBackground(false);
            QueryTittle->setStyleSheet(QString::fromUtf8(""));
            QueryTittle->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter);
            QueryResult_logo = new QLabel(QueryPage);
            QueryResult_logo->setObjectName(QString::fromUtf8("QueryResult_logo"));
            QueryResult_logo->setEnabled(true);
            QueryResult_logo->setGeometry(QRect(840, 90, 231, 211));
            QueryResult_logo->setStyleSheet(QString::fromUtf8("border: 0px"));
            QueryResult_logo->setScaledContents(true);
            QueryText = new QLabel(QueryPage);
            QueryText->setObjectName(QString::fromUtf8("QueryText"));
            QueryText->setGeometry(QRect(470, 300, 941, 101));
            QueryText->setFont(font1);
            QueryText->setAutoFillBackground(false);
            QueryText->setStyleSheet(QString::fromUtf8(""));
            QueryText->setAlignment(Qt::AlignCenter);
            QueryName = new QLabel(QueryPage);
            QueryName->setObjectName(QString::fromUtf8("QueryName"));
            QueryName->setGeometry(QRect(130, 500, 591, 101));
            QueryName->setFont(font2);
            QueryName->setAutoFillBackground(false);
            QueryName->setStyleSheet(QString::fromUtf8(""));
            QueryProfile = new QLabel(QueryPage);
            QueryProfile->setObjectName(QString::fromUtf8("QueryProfile"));
            QueryProfile->setGeometry(QRect(130, 590, 591, 101));
            QueryProfile->setFont(font2);
            QueryProfile->setAutoFillBackground(false);
            QueryProfile->setStyleSheet(QString::fromUtf8(""));
            QueryLastValInfo = new QLabel(QueryPage);
            QueryLastValInfo->setObjectName(QString::fromUtf8("QueryLastValInfo"));
            QueryLastValInfo->setGeometry(QRect(130, 680, 1651, 101));
            QueryLastValInfo->setFont(font2);
            QueryLastValInfo->setAutoFillBackground(false);
            QueryLastValInfo->setStyleSheet(QString::fromUtf8(""));
            QueryMaintButton = new QPushButton(QueryPage);
            QueryMaintButton->setObjectName(QString::fromUtf8("QueryMaintButton"));
            QueryMaintButton->setGeometry(QRect(20, 750, 61, 61));
            QueryMaintButton->setIconSize(QSize(50, 50));
            StackedWidget->addWidget(QueryPage);
    
            retranslateUi(MainWindow);
    
            StackedWidget->setCurrentIndex(1);
            
            QMetaObject::connectSlotsByName(MainWindow);
    
        } // setupUi
    
        void retranslateUi(QWidget *MainWindow)
        {
            MainWindow->setWindowTitle(QCoreApplication::translate("MainWindow", "MainWindow", nullptr));
            UOC_logo->setText(QString());
            Date->setText(QCoreApplication::translate("MainWindow", "--/--/----", nullptr));
            Time->setText(QCoreApplication::translate("MainWindow", "-:-:-", nullptr));
            ValidatePage->setWindowTitle(QCoreApplication::translate("MainWindow", "MainWindow", nullptr));
            ValText->setText(QCoreApplication::translate("MainWindow", "Por favor, acerque su tarjeta", nullptr));
            ValResult_logo->setText(QString());
            ValName->setText(QString());
            ValProfile->setText(QString());
            ValMaintButton->setText(QString());
            MaintTittle->setText(QCoreApplication::translate("MainWindow", "Men\303\272 de Mantenimiento", nullptr));
            MaintText1->setText(QCoreApplication::translate("MainWindow", "Selecci\303\263n de modo de operaci\303\263n", nullptr));
            MaintValButton->setText(QCoreApplication::translate("MainWindow", "Modo validaci\303\263n de tarjetas", nullptr));
            MaintQueryButton->setText(QCoreApplication::translate("MainWindow", "Modo consulta de tarjetas", nullptr));
            MaintBackButton->setText(QString());
            MaintText2->setText(QCoreApplication::translate("MainWindow", "Hist\303\263rico de transacciones", nullptr));
            QueryTittle->setText(QCoreApplication::translate("MainWindow", "Modo Consulta", nullptr));
            QueryResult_logo->setText(QString());
            QueryText->setText(QCoreApplication::translate("MainWindow", "Por favor, acerque su tarjeta", nullptr));
            QueryName->setText(QString());
            QueryProfile->setText(QString());
            QueryLastValInfo->setText(QString());
            QueryMaintButton->setText(QString());
        } // retranslateUi
    
    };
    
    namespace Ui {
        class MainWindow: public Ui_MainWindow {};
    } // namespace Ui
    
    QT_END_NAMESPACE
    
    #endif // UI_MAINWINDOW_H
    
    

    Thanks in advance,
    Pablo.



  • hello again!
    Finally i found what was making my application consume lot of memory, the images!
    If i comment the followin lines my application consume only 5% of the MEM.

    MainWindow->setStyleSheet(QString::fromUtf8("background : url(images/background.jpg)"));
    UOC_logo->setStyleSheet(QString::fromUtf8("background: url(images/uoc_logo.png)"));
    ValidatePage->setStyleSheet(QString::fromUtf8("background : url(images/background.jpg)"));
    

    I tried to add the sames images in other way and now is working ok, so sems to be something related with the setStyleSheet method.

    Thanks everyone.


  • Lifetime Qt Champion

    How big are the images, how did you solve it? When they're 1920x1080 then every image needs ~8MB in the RAM.



  • @Christian-Ehrlicher I think is not directly related with the images instead but with the setStylesheet method, now im using the same images.
    I deleted the StyleSheet value on QT Designer and on my QMainClass constructor i added the following lines:

        //! Set logo to button
        ui->UOC_logo->setPixmap(QPixmap(QString::fromUtf8("images/uoc_logo.png")));
    
        //! Set background
        QPixmap bkgnd("images/background.jpg");
        bkgnd = bkgnd.scaled(this->size(), Qt::IgnoreAspectRatio);
        QPalette palette;
        palette.setBrush(QPalette::Background, bkgnd);
        this->setPalette(palette);
    

    And now is working perfectly. Im new on Qt development and Qt Designer, so i dont really know why it happend....

    PD. The background image size is 2560x1440 and the logo image size 245x182.
    Regards.
    Pablo.


  • Lifetime Qt Champion

    Hi,

    A style sheet like you wrote will apply to all widgets that are child of the one you called setStylesheet on hence you likely had a faire amount of copies of your image which needs to be uncompressed in memory to be shown. A jpeg that is 2560x1440 will be pretty heavy especially if applied to several widgets.



  • Hi,

    It could explain why i was having this problem. Thanks for share your knowledge!

    Regards,
    Pablo.


Log in to reply