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. Center QFileDialog
Qt 6.11 is out! See what's new in the release blog

Center QFileDialog

Scheduled Pinned Locked Moved General and Desktop
18 Posts 3 Posters 11.2k 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.
  • G Offline
    G Offline
    goocreations
    wrote on last edited by
    #7

    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
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #8

      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
      0
      • G Offline
        G Offline
        goocreations
        wrote on last edited by
        #9

        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
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #10

          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
          0
          • G Offline
            G Offline
            goocreations
            wrote on last edited by
            #11

            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
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #12

              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
              0
              • G Offline
                G Offline
                goocreations
                wrote on last edited by
                #13

                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
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #14

                  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
                  0
                  • G Offline
                    G Offline
                    goocreations
                    wrote on last edited by
                    #15

                    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
                    0
                    • B Offline
                      B Offline
                      blex
                      wrote on last edited by
                      #16

                      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
                      0
                      • G Offline
                        G Offline
                        goocreations
                        wrote on last edited by
                        #17

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

                        1 Reply Last reply
                        0
                        • B Offline
                          B Offline
                          blex
                          wrote on last edited by
                          #18

                          [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
                          0

                          • Login

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