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. [SOLVE] How to set order show of Dialog?
Forum Updated to NodeBB v4.3 + New Features

[SOLVE] How to set order show of Dialog?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 1.9k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    phamvanan
    wrote on last edited by
    #1

    Hi all,
    I have 2 dialog such as: Dialog.cpp and Dialog2.cpp class
    in constructure's Dialog a call show Dialog2 as :
    @Dialog::Dialog(QWidget *parent) :
    QDialog(parent),_dialog2(NULL),
    ui(new Ui::Dialog)
    {
    ui->setupUi(this);
    if(_dialog2 == NULL){
    _dialog2 = new Dialog2();
    }
    _dialog2->show();
    }
    @
    Result is Dialog2 show precede and Dialog follow auto. But now I want reverse, Dialog will showed preceding and then Dialog2 showed.
    Brief, How to set order show of Dialog automatic? How to check a dialog actually showed in monitor?
    I try to:
    @ if(dialog1->isVisible()){
    dialog1->hide();
    dialog2->show();
    }
    @
    But I don't see the dialog1 appearance. Only dialog2 showed.

    -PVA-

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on last edited by
      #2

      The problem is that you are using _dialog2->show() inside the constructor of Dialog and I guess the instance to Dialog->show() is called later. AFAIK there is no automatic way to set the order in which the dialog will show, It completely depends when you want call show() function for a widget.

      So may be you can create an instance of dialog2 in the constructor and call _dialog2->show() when Dialog is already visible.

      You can override eventFilter() for Dialog class and then check for QEvent::Show or check QWidget::showEvent() and accordingly call _dialog2->show().

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bodzio131
        wrote on last edited by
        #3

        Main problem I see is that you couple 'order' logic with objects which are part of this logic: you create one dialog inside almost created another dialog, as pointed Sam. In my opinion you should create some kind of DialogOrderCreator which can create your dialogs in proper way, without any direct dependencies between your dialogs.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          phamvanan
          wrote on last edited by
          #4

          Hi all,
          Thank you for your help,
          I try to use:
          @void Dialog::showEvent(QShowEvent *showEvent){
          if(showEvent->type() == QEvent::Show){
          this->_dialog2->show();
          }
          }@
          but dialog1 also show preceding dialog2.
          Thanks.

          -PVA-

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

            Yes, showEvent() get called just before your Dialog display, so you still make dialog2 shown before dialog1
            [quote author="phamvanan" date="1374027544"]Hi all,
            Thank you for your help,
            I try to use:
            @void Dialog::showEvent(QShowEvent *showEvent){
            if(showEvent->type() == QEvent::Show){
            this->_dialog2->show();
            }
            }@
            but dialog1 also show preceding dialog2.
            Thanks. [/quote]

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

              [quote author="phamvanan" date="1373971710"]Hi all,
              I have 2 dialog such as: Dialog.cpp and Dialog2.cpp class
              in constructure's Dialog a call show Dialog2 as :
              Dialog::Dialog(QWidget *parent) :
              QDialog(parent),_dialog2(NULL),
              ui(new Ui::Dialog)
              {
              ui->setupUi(this);
              if(_dialog2 == NULL){
              _dialog2 = new Dialog2();
              }
              _dialog2->show();
              }
              [/quote]

              Just replace

              @
              _dialog2->show();
              @

              with

              @
              QTimer::singleShot(0, _dialog2, SLOT(show()));
              @

              should work.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                phamvanan
                wrote on last edited by
                #7

                Thank you very much.z

                -PVA-

                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