How to set image on QPushButton?

What you can do is use a pixmap as an icon and then put this icon onto the button. To make sure the size of the button will be correct, you have to reisze the icon according to the pixmap size. Something like this should work : QPixmap pixmap(“image_path”); QIcon ButtonIcon(pixmap); button->setIcon(ButtonIcon); button->setIconSize(pixmap.rect().size());

Qt Quick vs. Qt Widget [closed]

Note: In this answer, “Qt Widgets” refers to a Qt Widgets Application, selectable when creating a new Qt application. This is seven years after the question was first posted… but here’s my “objective” two cents to neutralise any developments since then. A Refresher Language Qt Quick projects use QML and JavaScript. The latter carries the … Read more

How to specify different Debug/Release output directories in QMake .pro file

For my Qt project, I use this scheme in *.pro file: HEADERS += src/dialogs.h SOURCES += src/main.cpp \ src/dialogs.cpp Release:DESTDIR = release Release:OBJECTS_DIR = release/.obj Release:MOC_DIR = release/.moc Release:RCC_DIR = release/.rcc Release:UI_DIR = release/.ui Debug:DESTDIR = debug Debug:OBJECTS_DIR = debug/.obj Debug:MOC_DIR = debug/.moc Debug:RCC_DIR = debug/.rcc Debug:UI_DIR = debug/.ui It`s simple, but nice! 🙂

Correct way to quit a Qt program?

QApplication is derived from QCoreApplication and thereby inherits quit() which is a public slot of QCoreApplication, so there is no difference between QApplication::quit() and QCoreApplication::quit(). As we can read in the documentation of QCoreApplication::quit() it “tells the application to exit with return code 0 (success).”. If you want to exit because you discovered file corruption … Read more

qmake: could not find a Qt installation of ”

sudo apt-get install qt5-default works for me. $ aptitude show qt5-default tells that This package sets Qt 5 to be the default Qt version to be used when using development binaries like qmake. It provides a default configuration for qtchooser, but does not prevent alternative Qt installations from being used.

QLabel: set color of text and background

The best and recommended way is to use Qt Style Sheet. Docs: Qt 5 Style Sheet, Qt 6 Style Sheet. To change the text color and background color of a QLabel, here is what I would do : QLabel* pLabel = new QLabel; pLabel->setStyleSheet(“QLabel { background-color : red; color : blue; }”); You could also … Read more

Auto-expanding layout with Qt-Designer

After creating your QVBoxLayout in Qt Designer, right-click on the background of your widget/dialog/window (not the QVBoxLayout, but the parent widget) and select Lay Out -> Lay Out in a Grid from the bottom of the context-menu. The QVBoxLayout should now stretch to fit the window and will resize automatically when the entire window is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)