1

I have searched for this topic but I seemingly cannot find a good solution for the following issue (for example discussed here):

I am currently doing some tutorials to get the hang of it. During the course of my trials, I now have a very simple Qt5 test GUI. The program itself starts very fast and the window immediately shows up, but the QPushButton is displayed with a 1-2 second(s) delay.

Here is the code i am using:

MainWindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QPushButton>

class MainWindow : public QMainWindow
{
    Q_OBJECT
    public:
        explicit MainWindow(QWidget *parent = nullptr);
    private slots:
        void handleButton();
    private:
        QPushButton *btnExit;
};

#endif // MAINWINDOW_H

MainWindow.cpp

#include "MainWindow.h"

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
    btnExit = new QPushButton("Exit", this);
    btnExit->setGeometry(QRect(QPoint(0, 0), QSize(75, 25)));
    connect(btnExit, SIGNAL(released()), this, SLOT(handleButton()));
}

void MainWindow::handleButton()
{
    this->close();
}

main.cpp

#include "mainwindow.h"
#include <QApplication>

using namespace std;

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    MainWindow mainWindow;
    mainWindow.show();
    return app.exec();
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.17)
project(qtgui)

set(CMAKE_CXX_STANDARD 14)

# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui)

set(SOURCE_FILES main.cpp MainWindow.cpp MainWindow.h)
add_executable(qtgui ${SOURCE_FILES})
target_link_libraries(qtgui Qt5::Core Qt5::Widgets Qt5::Gui)

I have a running Mingw64 environment in msys2 on Windows 10 with a fairly decent Laptop (8thGen I5 and an NVM), so speed should not be the issue here.

UPDATE

Here is a gif that shows the phenomenon:

click_me

I've also noticed the following warnings of my IDE (CLion):

qt.qpa.fonts: Unable to enumerate family ' "Droid Sans Mono Dotted for Powerline" ' qt.qpa.fonts: Unable to enumerate family ' "Droid Sans Mono Slashed for Powerline" ' qt.qpa.fonts: Unable to enumerate family ' "Roboto Mono Medium for Powerline" ' qt.qpa.fonts: Unable to enumerate family ' "Ubuntu Mono derivative Powerline" '

Could it be that fonts cause this delay?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
KamikaZimon
  • 65
  • 2
  • 8
  • Are you starting your application in debug mode? GDB under mingw used to spend lots of time on loading/unloading some system libs. – Vasilij Sep 24 '20 at 13:59
  • No, this problem persists in the release version as well – KamikaZimon Sep 24 '20 at 14:15
  • That is strange. I don't see anything in your code that can lead to such behavior. Maybe try to launch a release version on other machines? – Vasilij Sep 24 '20 at 14:45
  • It's probably related to the fonts. Maybe those issues delay the rendering of the button. You could try setting the application font to something like "Verdana", because I think the default is Ubuntu. https://code.woboq.org/qt5/qtbase/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp.html#1177 is where the warning / error comes from – deW1 Sep 24 '20 at 15:41
  • Thanks, I'll check that out – KamikaZimon Sep 24 '20 at 17:54
  • Have you tried calling show on the QPushbutton before the end of the MainWindow constructor? – Nick M. Sep 24 '20 at 23:06

0 Answers0