You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Tuesday, June 15th 2004, 12:35pm

Howto center or position a dialog on the screen

Newbie question:

How does one position a dialog to the center of the screen or indeed to any position on the screen regardless of its parent?

If QApplication is the parent then the dialog opens in the center on the screen, however if another QDialog is the parent, then dialog opens centered to the QDialog that called it.

I also cannot workout how to position a dialog before it is shown. I can move the dialog once show() is called but this movement can be seen by the user.

Thanks,
Royce

ppv

Trainee

  • "ppv" is male

Posts: 58

Location: belarus

Occupation: QT programmer

  • Send private message

2

Tuesday, June 15th 2004, 6:59pm

RE: Howto center or position a dialog on the screen

Quoted

Originally posted by RoyceyBaby
Newbie question:

How does one position a dialog to the center of the screen or indeed to any position on the screen regardless of its parent?

If QApplication is the parent then the dialog opens in the center on the screen, however if another QDialog is the parent, then dialog opens centered to the QDialog that called it.

I also cannot workout how to position a dialog before it is shown. I can move the dialog once show() is called but this movement can be seen by the user.

Thanks,
Royce



Try use method before call show reparent(...) , also you can use this method to show window without method show().

Posts: 2,162

Location: Graz, Austria

Occupation: Student

  • Send private message

3

Tuesday, June 15th 2004, 8:57pm

RE: Howto center or position a dialog on the screen

Quoted

Originally posted by RoyceyBaby
I also cannot workout how to position a dialog before it is shown.

Why not?

Cheers,
_
Qt/KDE Developer
Debian User

4

Wednesday, June 16th 2004, 2:40am

RE: Howto center or position a dialog on the screen

put the following code in the init() function
QRect scr = QApplication::desktop()->screenGeometry();
move( scr.center() - rect().center() );

5

Wednesday, June 16th 2004, 10:27pm

RE: Howto center or position a dialog on the screen

wulfgang:

I tried your code but the dialog still centres itself on the calling dialog instead of the screen.

Royce

samdutton

Intermediate

  • "samdutton" is male

Posts: 160

Location: Australian in London

Occupation: C++ and Web developer

  • Send private message

6

Thursday, June 17th 2004, 7:31am

RE: Howto center or position a dialog on the screen

I use QWidget::setGeometry() for dialogs.

Sam

7

Thursday, June 17th 2004, 11:00am

RE: Howto center or position a dialog on the screen

I have tried the following in a new project with just the one form

Source code

1
2
3
4
5
6
FormTest  *formTest;

formTest = new FormTest();
// (1)
formTest->show();
// (2)

If the code

Source code

1
formTest->setGeometry( 10, 10, 100, 100 );
is placed at point (1) then the form stays in the centre of the screen but is resized to 100x100. If the code is placed at point (2) then the form briefly appears in the centre of the screen and is moved to 10,10 and sized to 100x100.

I don't know what I am doing wrong. I don't like the flicker which occurs when i move the form after it is shown so I would prefer to place the form before it shows on the screen.

Thanks,
Royce

samdutton

Intermediate

  • "samdutton" is male

Posts: 160

Location: Australian in London

Occupation: C++ and Web developer

  • Send private message

8

Thursday, June 17th 2004, 11:12am

RE: Howto center or position a dialog on the screen

I put setGeometry in the constructor for my subclassed dialog -- not sure if that helps you.

Sam

9

Thursday, June 17th 2004, 11:47am

RE: Howto center or position a dialog on the screen

This may possibly be a KDE/X issue. I tried the code in the constructor and it had the same result.

So I tried to compile under windows and it works.

Does anybody have any more information?

Thanks,
Royce

10

Thursday, June 17th 2004, 4:47pm

RE: Howto center or position a dialog on the screen

I have confirmed this to be a KDE issue. If I run X without KDE then the window is placed correctly, if I am using KDE then the window is always placed in the centre of the screen.

Now for how to disable/bypass this functionality....


Royce

ppv

Trainee

  • "ppv" is male

Posts: 58

Location: belarus

Occupation: QT programmer

  • Send private message

11

Thursday, June 17th 2004, 5:07pm

RE: Howto center or position a dialog on the screen

try to use method

reparent( QWidget * parent, WFlags f, const QPoint & p, bool showIt = FALSE)


if (showIt =TRUE)
you can don't call show()


third parameter = position of your window at screen.

Posts: 2,162

Location: Graz, Austria

Occupation: Student

  • Send private message

12

Saturday, June 19th 2004, 1:57pm

You could try to overwrite showEvent() and do the move there.

The window manager can place a newly appearing window where ever it wants to, but perhaps you can configure its window placing strategy.

Cheers,
_
Qt/KDE Developer
Debian User

13

Wednesday, June 30th 2004, 11:33am

thanks to all!
by using reparent( QWidget * parent, WFlags f, const QPoint & p, bool showIt = FALSE); I did place my dialog to p point but if flags f = 0, my dialog is not a real dialog (I mean no my dialog had no border, title bar,... like a widget). And when I set flags f = WStyle_Dialog, my dialog appeared on center of the screen again.

Please help me, or I must come back to KDe 2.
thanks.

14

Wednesday, July 28th 2004, 5:20am

Return to Linux today after 1 month studying on Windows. By chance, I found a very simple solution for my application (without coding).

I did:
1. Move my dialog to desired position.
2. Turn on System menu by right click on title bar.
4. Turn on Store Window Settings option in Advanced sub menu.

Any beter solution???
Who do you think you are? ?(

15

Friday, June 17th 2005, 11:27am

Howto center or position a dialog on the screen?

Please take a look at this:
http://www.qtforum.org/thread.php?thread…dialog+position

uhm... The problem has not been solved yet! And my dialog still get displayed at center of screen.

Please help! I'm on Mandrake 10.2 (Mandiva); KDevelop 3.1.2 (Using KDE 3.3.2 and QT 3.3.4)
Who do you think you are? ?(

dimitri

Professional

  • "dimitri" is male

Posts: 1,311

Occupation: Engineer

  • Send private message

16

Friday, June 17th 2005, 2:32pm

RE: Howto center or position a dialog on the screen?

Quoted

Originally posted by huynux
Please take a look at this:
http://www.qtforum.org/thread.php?thread…dialog+position

Please don't start a new thread, you may add a comment to the existing thread instead.

bnortier

Beginner

  • "bnortier" is male

Posts: 5

Location: Cape Town, South Africa

Occupation: Software Engineer

  • Send private message

17

Wednesday, June 22nd 2005, 8:21am

I have exactly the same problem. I've also tried reparenting etc. but no solution. As soon as the Qt::WType_Dialog flag is set, the dialog is repositioned automatically. I'm actually adding my comment so I can receive email notifications of new posts :)

KDE
Redhat Enterprise Workstation 4
Qt 3.3.4
--------------------------------------------------------------------------
Benjamin Nortier
Software Engineer
EM Software and Systems (South Africa)
bnortier@emss.co.za
W: +27(0)21 880 1880
C: +27(0)82 693 2696
--------------------------------------------------------------------------

18

Wednesday, June 22nd 2005, 9:44am

Well, my application has many, so manay, dialogs. In fact, I must apply the following solution:

Source code

1
2
3
4
// set position 
myDialog->setGeometry(...);
// and show my dialog
myDialog->show();


It's OK but, you know, my monitor get blinked!
Who do you think you are? ?(