PDA

View Full Version : How to change initial visibilty in QTCreator?



t_s
20th May 2009, 20:18
I've noticed that there are no visibility options for any (well, can't say 100% but for all those I've used) widgets and if I add it (setVisible(0)/setVisible(false)) as a dynamic propery it is ignored.
Also since there is a bare minimum c-code generated by the ui-designer (why? can't do anything useful with the .ui-file that I can't do in the designer anyway) I can't manually change this. The only way for me to do it now is in the constructor of the main window which is a very ugly way of doing it IMO.

So my question is, how is one supposed to do it "properly" in the creator?

wysota
20th May 2009, 21:59
Visibility of what? As for the ui file, it is supposed to be that way. Read this: Using a Designer .ui File in Your Application

t_s
20th May 2009, 23:10
Visibility of what? As for the ui file, it is supposed to be that way. Read this: Using a Designer .ui File in Your Application

Errr...thanks for answering but did you read my post or just reply to the title? The initial visibilty of any widget (at run-time), controlled by setVisible, show, hide you name it. Perhaps there was something confusing in my initial post? :confused:

As for the other question, I'm yet to read through all that (tthe link). It's just that I'm used to utilizing IDE:s to generate a base code I then can edit to fit my purpose. I'm sure there are some smart concepts behind the QT approach, but a little frustrating when I get stuck as in my case above.

wysota
20th May 2009, 23:29
Perhaps there was something confusing in my initial post? :confused:
Yes there was. Don't abuse the word "Creator" because it leads to confusion. You should have asked about initial visibility of the form in your program that you create in Creator (or in fact Designer). Then I would have said that widgets are hidden by default and you should show() them in your code. Then you would have asked how to do that and then I would point you to the link I did point you to. So cutting to the chase - your question was answered by the link I gave you.


As for the other question, I'm yet to read through all that (tthe link)

Then read the link and the answer(s) to your question(s) will become obvious.


. It's just that I'm used to utilizing IDE:s to generate a base code I then can edit to fit my purpose. I'm sure there are some smart concepts behind the QT approach, but a little frustrating when I get stuck as in my case above.

You're used to stupid IDEs that don't give a damn about inheritance. Qt does so you do all that you say by subclassing and not editing auto-generated code.

And by the way - learning some things first before giving opinions about them is a really good idea. You got stuck because you started coding before learning and expected something to work exactly as you're used to with some other mechanism and finding that things are a bit different you assumed that everything must be different. Just as you didn't notice that the code generated from the .ui file is not a widget so calling show(), hide() or setVisible() on it wouldn't make any sense.

t_s
21st May 2009, 18:50
Yes there was. Don't abuse the word "Creator" because it leads to confusion. You should have asked about initial visibility of the form in your program that you create in Creator (or in fact Designer). Then I would have said that widgets are hidden by default and you should show() them in your code. Then you would have asked how to do that and then I would point you to the link I did point you to. So cutting to the chase - your question was answered by the link I gave you.

Mkay...now, I am confused. How come then I see every widget without having used a single show? You talk about inheritance and from what I've read before about how QT works, am I to assume that the show command (the only one I found in all of the code) used for the main window somehow affects all its children individually? :confused:
If so I really need to sit down and read through the docs.


And by the way - learning some things first before giving opinions about them is a really good idea.

Well, I mistakingly assumed I wouldn't need to re-learn much, which is my fault but then again I am posting in the newbie section of the forum so I am quite aware of that.


Just as you didn't notice that the code generated from the .ui file is not a widget so calling show(), hide() or setVisible() on it wouldn't make any sense.

I am not quite sure what you're talking about but what I do does work (which I assume it should?)

ui->nameofwdigetinquestion->setVisible(0); in the constructor of the main window works perfectly fine. I just thought there must be a much better way to do this (like through adding custom settings, setVisible and so on, in the form editor).

Anyway, skimming through that link and some other examples, as I understand it, if I want to custom-make a certain widget, I include the ui-file, re-declare a constructor with the same name, and customize it the way I want. Am I getting the hang of it or am I just far out there?

Again, thanks for taking the time, you're like the only person in three different qt-forums who has even bothered to try answer that question for me...

wysota
21st May 2009, 23:05
Mkay...now, I am confused. How come then I see every widget without having used a single show?
Probably thanks to that "show()" in your main() which I guess is there.


You talk about inheritance and from what I've read before about how QT works, am I to assume that the show command (the only one I found in all of the code) used for the main window somehow affects all its children individually? :confused:
Inheritance has nothing to do with it. With inheritance I was referring to your idea of modifying auto-generated code.

And yes, exactly as the docs say, making a widget visible makes all its children visible unless they were explicitely hidden.


If so I really need to sit down and read through the docs.

You do but not because of the reason you mentioned.


Well, I mistakingly assumed I wouldn't need to re-learn much, which is my fault but then again I am posting in the newbie section of the forum so I am quite aware of that.
But still you make firm statements about what is and what is not.


I am not quite sure what you're talking about but what I do does work (which I assume it should?)
Then take a text editor, open the file generated from your ui file (which is called ui_nameofthefile.h) and check its contents. Happy "enlightening".



ui->nameofwdigetinquestion->setVisible(0); in the constructor of the main window works perfectly fine.
Sure it does. "ui->nameofwidgetinquestion" is a widget while "ui" is not.


I just thought there must be a much better way to do this (like through adding custom settings, setVisible and so on, in the form editor).
Yes, there is. Simply call "show()".


Anyway, skimming through that link and some other examples, as I understand it, if I want to custom-make a certain widget, I include the ui-file, re-declare a constructor with the same name, and customize it the way I want. Am I getting the hang of it or am I just far out there?
You are wrong but not very far from the truth. You can either follow the is-a concept (by inheriting the ui component) or the has-a concept (by making it a member of your widget subclass). You don't touch the constructor of the ui component but you implement the constructor of your subclass of the widget class. Just as written in the docs.


Again, thanks for taking the time, you're like the only person in three different qt-forums who has even bothered to try answer that question for me...

That's because this is the Ultimate Qt Community site, not just some forum ;)

t_s
22nd May 2009, 12:15
Heh, do I feel dense now or what (I finally managed to figure it all out this morning)???
Anyway, many thanks for helping me help myself.. :D