Important: Please read the Qt Code of Conduct -

How to create 'x' CLOSE/ EXIT button on the dialog Box?

  • Hey! I am Burhan
    I am working on a periodic table in Qt c++. Belle Symbian.
    The theme is when you click on the button of an element the properties of the respective element appears in the dialog and the dialog contains information about the element and the back/ close button.
    Before working on the periodic table and design all buttons i want to test a one first.
    I have stuck. i don't know how to create a 'x' close/ back button on the dialog.

    CAN anyone PLEASE tell me how to create a close button on the dialog.????? :( I am just a starter so please suggest me the easy way.
    Thanks. Awaiting for your reply.

  • If you use the static function of a QMessageBox::information you can enter all the stuff you want. Qt will handle the close 'x' automatic and if you want you can add the normal ok/cancel buttons if needed using the StandardButton enum. Just check out the QMessageBox for more information. If you set the parent with 'this' all other functions will be halted until the messagebox is closed. If that isn't want you want you are able to set the setModal to alter it so multiple messageboxen can be opened.
    Greetz and have fun!

  • Thanks buddy for the suggestion. I have to do it through dialog box.
    @#include "hydrogen.h"
    #include "ui_hydrogen.h"
    #include <QLabel>
    #include <QtGui>
    #include <QtCore>

    Hydrogen::Hydrogen(QWidget *parent) :
    ui(new Ui::Hydrogen)
    Hydrogen :: hydinfo();

    delete ui;
    void Hydrogen :: hydinfo(void)
    QGridLayout *layout = new QGridLayout;
    QLabel *name = new QLabel ("Name");
    layout->addWidget(name, 0, 0);

    QLabel *sym = new QLabel ("Symbol");
    layout->addWidget(sym, 1,0);
    QLabel *sym2 = new QLabel ("H");
    layout->addWidget(sym2, 1,1);

    QLabel *chemser = new QLabel ("Chemical Series");
    layout->addWidget(chemser, 2,0);
    QLabel *chemser2 = new QLabel ("Non-Metals");
    layout->addWidget(chemser2, 2,1);
    Hydrogen :: setLayout(layout);
    Hydrogen :: show();

    Like this... but when i deploy it on C7 it doesn't show any close button :/

  • if you want to add a "back" button on the bottom of the dialog: just add
    QPushButton *backButton= new QPushButton;
    connect (backButton,SIGNAL(clicked()),this,SLOT(hide()));
    just before the Hydrogen :: setLayout(layout); line in the hydinfo() method

  • @VRonin: Done Successfully!
    Thanks in tons =)

Log in to reply