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. CDialog OnInitDialog()
QtWS25 Last Chance

CDialog OnInitDialog()

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.1k 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by Perdrix
    #1

    I'm porting a lot a MFC code to Qt right now.

    Most of the CDialog derived dialogues don't initialise everything in the ctor. MFC programmers often construct the dialogues, then maybe invoke a few methods to configure this or that and then call (e.g.) DoModal() to display the dialogue. At this point (just before the dialogue is displayed), the OnInitDialog() method is invoked:

    "Override this method if you want to perform special processing when the dialog box is initialized. In the overridden version, first call the base class OnInitDialog but ignore its return value. You will typically return TRUE from your overridden method."

    Is there a method/slot in QDialog that I can override that is called immediately before the dialogue is displayed using e.g. show() or exec()?

    Thanks
    David

    JonBJ 1 Reply Last reply
    0
    • PerdrixP Perdrix

      I'm porting a lot a MFC code to Qt right now.

      Most of the CDialog derived dialogues don't initialise everything in the ctor. MFC programmers often construct the dialogues, then maybe invoke a few methods to configure this or that and then call (e.g.) DoModal() to display the dialogue. At this point (just before the dialogue is displayed), the OnInitDialog() method is invoked:

      "Override this method if you want to perform special processing when the dialog box is initialized. In the overridden version, first call the base class OnInitDialog but ignore its return value. You will typically return TRUE from your overridden method."

      Is there a method/slot in QDialog that I can override that is called immediately before the dialogue is displayed using e.g. show() or exec()?

      Thanks
      David

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Perdrix
      Yes, you need to sub-class and override QWidget::showEvent(), https://doc.qt.io/qt-5/qwidget.html#showEvent, for any widget, including QDialog.

      J 1 Reply Last reply
      3
      • JonBJ JonB referenced this topic on
      • JonBJ JonB

        @Perdrix
        Yes, you need to sub-class and override QWidget::showEvent(), https://doc.qt.io/qt-5/qwidget.html#showEvent, for any widget, including QDialog.

        J Offline
        J Offline
        jdent
        wrote on last edited by
        #3

        @JonB I do this code:

        void LocationDlg::showEvent(QShowEvent* event)
        {
            QSize sizeOfTableView = tableView->size();
            QSize sizeOfWindow = this->size();
            resize(sizeOfTableView.width(), sizeOfWindow.height());
        
            QDialog::showEvent(event);
        }
        

        But the window is not the width of the QTableView!!!

        1720a305-8f42-4d57-933d-752498d81f48-image.png

        See?

        JonBJ 1 Reply Last reply
        0
        • J jdent

          @JonB I do this code:

          void LocationDlg::showEvent(QShowEvent* event)
          {
              QSize sizeOfTableView = tableView->size();
              QSize sizeOfWindow = this->size();
              resize(sizeOfTableView.width(), sizeOfWindow.height());
          
              QDialog::showEvent(event);
          }
          

          But the window is not the width of the QTableView!!!

          1720a305-8f42-4d57-933d-752498d81f48-image.png

          See?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @jdent said in CDialog OnInitDialog():

          See?

          Not really, no. Window looks to be the width of the table view to me.

          If you mean you think the table view is first going to be full-width (so no horizontal scroll) and then the dialog will resize its width to that I would not expect that behaviour,

          Did you try debugging out the size values?

          Other than that I might try putting the base call QDialog::showEvent(event); before rather than after the size() calls as that might influence their values?

          J 1 Reply Last reply
          0
          • JonBJ JonB

            @jdent said in CDialog OnInitDialog():

            See?

            Not really, no. Window looks to be the width of the table view to me.

            If you mean you think the table view is first going to be full-width (so no horizontal scroll) and then the dialog will resize its width to that I would not expect that behaviour,

            Did you try debugging out the size values?

            Other than that I might try putting the base call QDialog::showEvent(event); before rather than after the size() calls as that might influence their values?

            J Offline
            J Offline
            jdent
            wrote on last edited by
            #5

            @JonB No I switched to:

            void LocationDlg::showEvent(QShowEvent* event)
            {
                QDialog::showEvent(event);
            
                QSize sizeOfTableView = tableView->size();
                QSize sizeOfWindow = this->size();
                resize(sizeOfTableView.width(), sizeOfWindow.height());
            }
            

            but the size of the table view is less than that of the window.....
            I need the full size of the table view as in the sum of the widths of its columns...

            JonBJ 1 Reply Last reply
            0
            • J jdent

              @JonB No I switched to:

              void LocationDlg::showEvent(QShowEvent* event)
              {
                  QDialog::showEvent(event);
              
                  QSize sizeOfTableView = tableView->size();
                  QSize sizeOfWindow = this->size();
                  resize(sizeOfTableView.width(), sizeOfWindow.height());
              }
              

              but the size of the table view is less than that of the window.....
              I need the full size of the table view as in the sum of the widths of its columns...

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @jdent
              You show a screenshot where so far as I can see the table view fills the width of the dialog. So you may know what else you mean, and perhaps someone else will, but I do not.

              I now see you have created https://forum.qt.io/topic/155541/how-do-i-iterate-across-the-columns-of-a-qtableview-so-i-can-find-the-total-width-of-the-table. I assume that is now the question you wish to ask. It would nice if you took the time to cross-reference from that question to this and vice versa so that people knew and did not spend time trying to answer both....

              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