Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Center QFileDialog

    General and Desktop
    3
    18
    9141
    Loading More Posts
    • 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.
    • G
      goocreations last edited by

      If I call:

      @QFileDialog::getOpenFileName(this, tr("Open Project"));@

      were this is a QMainWindow, the file dialog is not centered. According to the Qt documentation the dialog should be centered if the "parent is not 0". I'm using Win7 (64bit) and Qt 4.7

      Does anyone know why this dialog is not centered? I've also tried to change the parent to another widget, but without any success.

      1 Reply Last reply Reply Quote 0
      • G
        goetz last edited by

        Where does the dialog pop up? According to the docs it should be centered over the parent widget, not the whole screen.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply Reply Quote 0
        • G
          goocreations last edited by

          it pops up at the top left corner of my parent widget, not the center of my parent widget

          1 Reply Last reply Reply Quote 0
          • G
            goetz last edited by

            Could you provide a short sample with source code so that we can have a detail look at it?

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply Reply Quote 0
            • G
              goocreations last edited by

              well, the line provided above is all the source code. I only have a button, and this is the only like in the mouse-clicked event function.

              1 Reply Last reply Reply Quote 0
              • G
                goetz last edited by

                mouse-clicked event function? Are you overriding one of the event handlers (mousePressEvent(), mouseReleaseEvent())? If so, of what type is the this pointer in your call? Or are you in a slot connected to the clicked signal of your button?

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply Reply Quote 0
                • G
                  goocreations last edited by

                  I'm not 100% sure what you are asking, I'm just overriding the mouse-clicked event of the button. I'm not sure of what pointer you are talking. And does this influence the QFileDialog events?

                  @void XapoWindow::on_loadButton_clicked()
                  {
                  QFileDialog::getOpenFileName(this->ui->centralWidget, tr("Open Xapo Project"));
                  }@

                  1 Reply Last reply Reply Quote 0
                  • G
                    goetz last edited by

                    From what you write, it seems that XapoWindow is of type "QMainWindow":http://doc.qt.nokia.com/4.7/qmainwindow.html. In that case, you should use this (i.e. your main window) as the parent to getOpenFileName(), not the centralWidget.

                    Just for your information: in XapoWindow::on_loadButton_clicked() you do not override a mouse event, in Qt world this is called a slot, that got automatically connected to the signal clicked of your button. See "Signals & Slots":http://doc.qt.nokia.com/4.7/signalsandslots.html and "The Event System":http://doc.qt.nokia.com/4.7/eventsandfilters.html in the Qt docs for some further information and the differences between the two.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply Reply Quote 0
                    • G
                      goocreations last edited by

                      Thanks for that, and yes, this is of type QMainWindow. I use that as parent, but the dialog is still not centered

                      1 Reply Last reply Reply Quote 0
                      • G
                        goetz last edited by

                        So it would be helpful if you could post the complete source code of your sample program or provide a download link. Otherwise we cannot look into the details or reproduce the faulty behaviour.

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        1 Reply Last reply Reply Quote 0
                        • G
                          goocreations last edited by

                          main.cpp:

                          @#include <QtGui/QApplication>
                          #include "XapoInterface/xapowindow.h"

                          int main(int argc, char *argv[])
                          {
                          QApplication a(argc, argv); //just using it as debug command line
                          XapoWindow w;
                          w.show();
                          return a.exec();
                          }@

                          XapoWindow.h:

                          @#ifndef XAPOWINDOW_H
                          #define XAPOWINDOW_H

                          #include <QMainWindow>
                          #include <QFileDialog>

                          namespace Ui {
                          class XapoWindow;
                          }

                          class XapoWindow : public QMainWindow
                          {

                          Q_OBJECT
                          

                          public:

                          /*
                           A constructor for creating a window
                           */
                          explicit XapoWindow(QWidget *parent = 0);
                          
                          /*
                           A destructor for destructing the window
                           */
                          ~XapoWindow();
                          

                          private:

                          Ui::XapoWindow *ui;
                          

                          private slots:

                          void on_loadButton_clicked();
                          

                          };

                          #endif // XAPOWINDOW_H@

                          XapoWindow.cpp:

                          @#include "XapoInterface/xapowindow.h"
                          #include "ui_xapowindow.h"

                          XapoWindow::XapoWindow(QWidget *parent) :
                          QMainWindow(parent),
                          ui(new Ui::XapoWindow)
                          {
                          ui->setupUi(this);
                          }

                          XapoWindow::~XapoWindow()
                          {
                          delete ui;
                          }

                          void XapoWindow::on_loadButton_clicked()
                          {
                          QFileDialog::getOpenFileName(this->ui->centralWidget, tr("Open Xapo Project"));
                          }
                          @

                          The XapoWindow is supported by 'n UI-file, I don't think you want it (or do you?), it is just a window with a button on it.

                          1 Reply Last reply Reply Quote 0
                          • G
                            goetz last edited by

                            Without the .ui file and the .pro file we cannot compile the program.

                            http://www.catb.org/~esr/faqs/smart-questions.html

                            1 Reply Last reply Reply Quote 0
                            • G
                              goocreations last edited by

                              Sorry for the late reply, here is the source code

                              http://www.goocreations.com/products/Basic.zip

                              OR

                              http://rapidshare.com/files/433719790/Basic.zip

                              Thank you!!

                              1 Reply Last reply Reply Quote 0
                              • G
                                goetz last edited by

                                I can reproduce the behaviour, but unfortnately I don't have any solution. Maybe it's a bug - you should consider reporting it at http://bugreports.qt.nokia.com.

                                http://www.catb.org/~esr/faqs/smart-questions.html

                                1 Reply Last reply Reply Quote 0
                                • G
                                  goocreations last edited by

                                  Thanks, I registered and found the same bug, reported in 2009.
                                  The ticket was closed with a resolution of "out of scope". So it seems it will not be fixed soon

                                  But thanks anyway for your help Volker

                                  1 Reply Last reply Reply Quote 0
                                  • B
                                    blex last edited by

                                    The workaround is simple. The geometry of the parent is available, the geometry of the dialog is also may be obtained.


                                    Oleksiy Balabay

                                    1 Reply Last reply Reply Quote 0
                                    • G
                                      goocreations last edited by

                                      but then you have to use the Qt file dialog, not the Windows-native dialog

                                      1 Reply Last reply Reply Quote 0
                                      • B
                                        blex last edited by

                                        [quote author="goocreations" date="1291014508"]but then you have to use the Qt file dialog, not the Windows-native dialog[/quote]

                                        You are right, sorry


                                        Oleksiy Balabay

                                        1 Reply Last reply Reply Quote 0
                                        • First post
                                          Last post