March 13, 2011

Delay Delay
Lab Rat
5 posts

Resize a dialog box

 

Hi folks,

How do I create a dialog box with hidden features to appear after a click of a button, like when a user wants to see the advanced options, then clicks an “advance” button and the dialog expands.
I already know how to make the widgets come and go, but I can’t make the window automatically resizes.

I appreciate any help.

 Signature 

“No one can go back to the past and make a new beginning, but anyone can start now and make a new ending.” Chico Buarque de Holanda

11 replies

March 13, 2011

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts

you connect the clicked of advance to a slot, in which you just do dialog->resize(w,h) and that should work!

else, post your code here

March 13, 2011

mlong mlong
Mad Scientist
1517 posts

You might check out this post [qtcentre.org] which I think covers what you’re talking about.

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

March 13, 2011

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts

mlong that seems to be an older post dealing with Qt3 … I just tried this:
1. used designer to add a dialog and added a pushbutton to this dialog
2. added signal slot to resize on button click

and it just works

March 13, 2011

mlong mlong
Mad Scientist
1517 posts

@chetankjain: I believe it is a Qt4-related thing. The example is basically showing how to use QLayout::setSizeConstraint to replace the old Qt3 QDialog::setResizeMode() functionality.

I think resize() is ok if you know a fixed size you want to expand to, but this method allows the QLayout to determine the new size of the dialog. Often, especially when working with i18n and translations, or with differing system themes, you can’t be sure of the size your dialog will need to be without having to do some dirty work with size hints and whatnot.

Whichever way works best is left as an exercise to the programmer. I’m just sharing an alternative that has worked for me.

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

March 13, 2011

Delay Delay
Lab Rat
5 posts

Thanks a lot,

The chetankjain’s idead works fine, I had to use the trial and error aproach, but it was fun.

mlong did present a more automatic way of doing this, but somehow it doesn’t work! The application suposedly executes but nothing appears on the screen, and after 18 to 20 seconds I get this:

Starting C:\Qt\2010.05\SortDialog-build-desktop\debug\SortDialog.exe…
C:\Qt\2010.05\SortDialog-build-desktop\debug\SortDialog.exe exited with code -1073741819

Runnig in debugging mode returns an error coming from the

layout()->setSizeConstraint(QLayout::SetFixedSize);

It says:

“The inferior stopped because it received a signal from the Operating System.

Signal name: SIGSEGV
Signal meaning: Segnentation fault”

I have no idea of what this means.

 Signature 

“No one can go back to the past and make a new beginning, but anyone can start now and make a new ending.” Chico Buarque de Holanda

March 13, 2011

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts

ah SIGSEGV:)
http://en.wikipedia.org/wiki/SIGSEGV [en.wikipedia.org]

March 13, 2011

Delay Delay
Lab Rat
5 posts

Looks like a Windows 7 kind of problem. I’ll just stick with the solution that works for me. If someone finds out what’s going on with my setSizeConstraint I’ll come back to this.

Thanks everyone for the support.

 Signature 

“No one can go back to the past and make a new beginning, but anyone can start now and make a new ending.” Chico Buarque de Holanda

March 13, 2011

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts

delay, if you could post your code one of us will look at it @ setSizeConstraint issue

March 13, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

Delay wrote:
Hi folks,

How do I create a dialog box with hidden features to appear after a click of a button, like when a user wants to see the advanced options, then clicks an “advance” button and the dialog expands.
I already know how to make the widgets come and go, but I can’t make the window automatically resizes.

I appreciate any help.

you can have a look at the example of the docs: dialog extension [doc.qt.nokia.com]

It works without fixed sizes

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

March 14, 2011

Delay Delay
Lab Rat
5 posts

Thank you Gerolf, it really helped. I used the idea of working with connections, but instead of dealing with multiple layouts I used only a single layout and resized it as required.
Setting a fixed size for the form’s layout in Qt Designer makes the resizing not avaiable to the user and lets the resizing through code a litle bit easier, since I can just put high values and the widget sizer puts it in the ideal size.

That’s the solution I’ll stick to.

Thank you everybody.

 Signature 

“No one can go back to the past and make a new beginning, but anyone can start now and make a new ending.” Chico Buarque de Holanda

March 14, 2011

mlong mlong
Mad Scientist
1517 posts

No problem! I think a lot of good ideas were shared. I’d forgotten about Gerolf’s example, as well. Good luck with your app!

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

 
  ‹‹ Minimizing Application to Tray      How can i calculate Qstring data ? ››

You must log in to post a reply. Not a member yet? Register here!