Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using Customized Dialog Boxes
QtWS25 Last Chance

Using Customized Dialog Boxes

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • DarthFutuzaD Offline
    DarthFutuzaD Offline
    DarthFutuza
    wrote on last edited by
    #1

    Hi there, I'm a bit of a noob when it comes to Qt programming, so if I say something extremely revealing of my noviceness, please forgive me.

    So I have an application, and so far for all the dialogs I've just been using code directly to make dialogs.

    eg:
    @void Dialog::informationMessage()
    {
    QMessageBox::StandardButton reply;
    reply = QMessageBox::information(this, tr("QMessageBox::information()"), MESSAGE);
    if (reply == QMessageBox::Ok)
    informationLabel->setText(tr("OK"));
    else
    informationLabel->setText(tr("Escape"));
    }@

    However, now I want to use a custom created dialog box when a button is pressed. I'm just not sure how to do it. My main function works something like this:
    @
    int main(int argc, char *arg[])
    {
    QApplication a(argc, argv);
    Launcher *w = Launcher::getSingleton();
    w->show();
    int ret = a.exec();
    return ret;
    }
    @

    My Launcher.h source file's work something like this:
    @
    class Launcher : public QMainWindow
    {
    Q_OBJECT

    public:
    Launcher(QWidget *parent = 0, Qt::WFlags flags = Qt::FramelessWindowHint);
    ~Launcher();

    static Launcher *getSingleton();
    //public functions

    private:
    Ui::LauncherClass ui;

    //rest of functions

    @

    Anyway from my Launcher.cpp file I want to have a function that when called, will create a new Ui::CustomDialogClass ui; and allow me to use a customized dialog box I've created, but I'm not sure exactly how I should go about doing it as this "public QMainWindow" is used by my Launcher.h and its not really a "QMainWindow" its more of a "QSubWindow". Anyway if someone could point me in the right direction that'd be super awesome. Thanks!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      I would recommend you to go through the examples in the Qt documentation, you'll have a good base to do what you want to achieve.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • DarthFutuzaD Offline
        DarthFutuzaD Offline
        DarthFutuza
        wrote on last edited by
        #3

        Thanks for the reply. However, I've been looking through some of the examples. eg: http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html

        Problem is all of them seem to use widget's. I just want a dialog box, not a widget. Am I confusing what Widget's actually are?

        Some sample code looked promising:
        @
        QWidget *widget = new QWidget;
        Ui::CalculatorForm ui;
        ui.setupUi(widget);

         widget->show();
         return app.exec();
        

        @
        But...I'm not so sure about the QWidget stuff. I thought I just wanted a dialog box, but it doesn't seem to allow me to do that except as a main dialogue. And apparently I can't have more than 1 of those. :(

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          QDialog is a specialized QWidget, if you need a QDialog, simply use it in place of QWidget. You can also go through the examples given in QDialog's documentation, they'll show you various ways of using it.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • DarthFutuzaD Offline
            DarthFutuzaD Offline
            DarthFutuza
            wrote on last edited by
            #5

            So I couldn't figure out how to get QDialog's to work so I just switched to using widgets and then did this:

            @ SettingDialogues *object = new SettingDialogues(this);
            object->setWindowFlags(Qt::Dialog); //make the object be a dialog
            object->show();@

            Seems to be the trick, I had to change my ui to a widget in order to get it to work. Hopefully I can figure the process out for Dialog's.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dbzhang800
              wrote on last edited by
              #6

              If you find it's hard to understand, maybe a C++ book is useful for you at present.

              1 Reply Last reply
              0
              • DarthFutuzaD Offline
                DarthFutuzaD Offline
                DarthFutuza
                wrote on last edited by
                #7

                Well its not really hard to understand c++ itself, I need a Qt specific book :D. I understand c++ well enough, I'm just not use to how Qt works. I'm sure I'll get better at using it, the more I use Qt based stuff.

                Regardless, I was able to get it working with QDialog's later today, it was a simple mistake really. I had just initially declared it as a QWidget in my .h file, instead of a QDialog which was causing the problem.

                Thanks for y'alls help though.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved