Qt C++ Tutorials For Beginners – Setting Icon on QMessageBox




Qt Tutorials For Beginners
Qt Tutorials For Beginners

Qt  C++ Tutorials For Beginners – Setting Icon on QMessageBox

The code below shows how to set custom icons on QMessageBox using qt creator.

Step 1 – File->Other Project->Empty Qt Project

When we create aEmpty Qt Project There is nothing in the Project explorer, and even the .pro file has nothing in it. So, we need to create a main.cpp file.

Step 2 – Right Click on Project -> Add New -> C++ -> C++ Source file -> Choose

And Give the name main.cpp file and press finish.

main.cpp

#include <QApplication>
#include <QMessageBox>

int main(int argc,char** argv)
{
  QApplication app(argc,argv);

  QMessageBox messageBox;
  messageBox.setIconPixmap(QPixmap("coffee-cup-icon.png"));
  messageBox.setText("This QMessageBox is with\ncustom icon !!!");
  messageBox.setWindowTitle("QMessageBox with Custom Icon..");
  messageBox.show();

  return app.exec();
}

.pro file

TARGET = Sample

QT = core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES += \
    main.cc

Setting Icon on QMessageBox
Setting Icon on QMessageBox

Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*