The usage of QMessageBox in QT Chinese button, set background, window LOGO

QMessageBox is a message prompt interface class that QT comes with. It is also more convenient to use. For projects developed with QT on the ARM board, it is used very frequently, saving us a lot of code. So the procedure is clearer.

1. The most basic call:

    QMessageBox::information(this,tr("hint"),tr("Are you sure to exit?"));


2. We are often not satisfied with such simple use. For example, I want to add a Chinese button:

   QMessageBox mess(QMessageBox::Information,tr("_new"),tr("打开失败"));
    QPushButton *okbutton = (mess.addButton(tr("确定"),QMessageBox::AcceptRole));
    mess.exec();

    if(mess.clickedButton==okbutton){...}


3. We are often not satisfied with such simple use. For example, I want to add a window background:

Add in the above code:

   mess.setStyleSheet("backgroud-image:1.jpg");


4. We are often not satisfied with such simple use, for example, I want to add a form LOGO:

Add in the above code:

    QIcon *icon = new QIcon(":/image/logo.ico");
    mess.setWindowIcon(*icon);


In fact, it is mainly to define an object of QMessageBox, which can be operated at will.

QMessageBox is a message prompt interface class that QT comes with. It is also more convenient to use. For projects developed with QT on the ARM board, it is used very frequently, saving us a lot of code. So the procedure is clearer.

1. The most basic call:

    QMessageBox::information(this,tr("hint"),tr("Are you sure to exit?"));


2. We are often not satisfied with such simple use. For example, I want to add a Chinese button:

   QMessageBox mess(QMessageBox::Information,tr("_new"),tr("打开失败"));
    QPushButton *okbutton = (mess.addButton(tr("确定"),QMessageBox::AcceptRole));
    mess.exec();

    if(mess.clickedButton==okbutton){...}


3. We are often not satisfied with such simple use. For example, I want to add a window background:

Add in the above code:

   mess.setStyleSheet("backgroud-image:1.jpg");


4. We are often not satisfied with such simple use, for example, I want to add a form LOGO:

Add in the above code:

    QIcon *icon = new QIcon(":/image/logo.ico");
    mess.setWindowIcon(*icon);


In fact, it is mainly to define an object of QMessageBox, which can be operated at will.

Guess you like

Origin blog.csdn.net/qq_16488989/article/details/109024570