Center QFileDialog
-
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.
-
it pops up at the top left corner of my parent widget, not the center of my parent widget
-
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.
-
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"));
}@ -
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.
-
Thanks for that, and yes, this is of type QMainWindow. I use that as parent, but the dialog is still not centered
-
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.
-
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!!
-
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.
-
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 soonBut thanks anyway for your help Volker
-
but then you have to use the Qt file dialog, not the Windows-native dialog