PDA

View Full Version : Hide QWidget Window on Application Startup



.Tommy.
15th November 2016, 08:57
Hi.

I'm trying to modify an existing app with two .ui files from which I compiled a Qt project and everything is good so far except for the changes I made to hide one of the ui files at application startup.

It works if I run the generated exe, but not when I open the original app.

I only changed line 15 in the main.cpp from show to hide:


#include "ExtendFrame.h"
#include "MiniFrame.h"
#include "ui_ExtendFrame.h"
#include "ui_MiniFrame.h"
#include <QApplication>
#include <QtGui>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
miniplugin_bgwidget w;
w.show();

miniplugin_bg x;
x.hide();

return a.exec();
}

No changes are applied to the actual ui files.

Please someone give me hint.

anda_skoa
15th November 2016, 09:43
If you don't show a window, it won't be visible, so no need to hide() it.

So if you only want the first window to show initially, just call w.show() and not x.show()

Cheers,
_

.Tommy.
15th November 2016, 13:24
....... thanks for your reply but I think you misunderstood.
This is an existing app which uses two ui files (2 windows in qt project).
In the original app these 2 windows are connected to each other on app start.
One is the main app and the other is a slide out menu below the app which can be closed and opened by a qpushbutton and I want this to be hidden on start, only open it when needed with the qpushbutton.
As I said, the app is working in Qt Creator as I want and also with the generated exe, but I don't need the exe file, I need only the ui files and there is no change in the ui file after applying hide()
As by your suggestion, the 1st window has w.show(); already and the one I want to hide has x.hide(); because having both with w.show(); or w.hide(); gives an error when debugging.
The question is how do I get the ui files updated when compiling the project ?
Do I need to edit another file in this project to accomplish this ...?...

anda_skoa
15th November 2016, 13:53
So this is not about hiding a widget at startup as your title suggests?

I also don't see how this has anything to do with UI files, these are irrelevant during runtime as they have been processed into code at buil time and that code has been used to populate the widgets.

Your code snippet needlessly includes the generated headers btw, those are already used by the two widgets internally.

Cheers,
_

.Tommy.
16th November 2016, 16:58
....... the way I understand it's not possible to do the job in Qt Creator at least for me it isn't.

Anyway, I added this property to the ui file (outsite Q Creator):


<property name="visible">
<bool>false</bool>
</property>

It works ok except for the QPushButton which is in the other ui file:


<widget class="QPushButton" name="miniplugin_modalExtendApp">
<property name="geometry">
<rect>
<x>153</x>
<y>320</y>
<width>63</width>
<height>20</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>63</width>
<height>20</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>63</width>
<height>20</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
<property name="CLASSID" stdset="0">
<string>F367D78A-0578-FBC4-A89E-65CB0AB3CCEC</string>
</property>
</widget>

Can this code be edited to make the QPushButton work again to open and close like before the property edit in the other ui file ...?...

anda_skoa
17th November 2016, 11:05
....... the way I understand it's not possible to do the job in Qt Creator at least for me it isn't.

Don't see what would not work in QtCreator



Anyway, I added this property to the ui file (outsite Q Creator):

Editing the UI code can also be done in QtCreator.




<property name="visible">
<bool>false</bool>
</property>

The visible property of what?



It works ok except for the QPushButton which is in the other ui file:


<widget class="QPushButton" name="miniplugin_modalExtendApp">
<property name="geometry">
<rect>
<x>153</x>
<y>320</y>
<width>63</width>
<height>20</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>63</width>
<height>20</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>63</width>
<height>20</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
<property name="CLASSID" stdset="0">
<string>F367D78A-0578-FBC4-A89E-65CB0AB3CCEC</string>
</property>
</widget>

Aside from the fixed size this looks like a normal UI part for a QPushButton.
What did you change? What is not working?



Can this code be edited to make the QPushButton work again to open and close like before the property edit in the other ui file ...?...
That is not in the UI file, there is some slot connected to the button's clicked() signal that does that.
It is totally uneffected by changes to the button's UI code.

Cheers,
_

.Tommy.
19th November 2016, 11:06
....... here the answer to a few of your questions


The visible property of what?

Line 32, 33, 34 in the code below.
It's not the full code of the ui, because it would be to long.
The full code can be seen in the attached 12220



<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>miniplugin_bg</class>
<widget class="QWidget" name="miniplugin_bg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>328</width>
<height>147</height>
</rect>
</property>
<property name="windowTitle">
<string>Mobile Partner</string>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="X" stdset="0">
<number>63</number>
</property>
<property name="Y" stdset="0">
<number>337</number>
</property>
<property name="Length" stdset="0">
<number>52</number>
</property>
<widget class="QLabel" name="AppUIPlugin_bglabel">
<property name="enable">
<bool>true</bool>
</property>
<property name="visible">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>328</width>
<height>147</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>328</width>
<height>147</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>328</width>
<height>147</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>



Aside from the fixed size this looks like a normal UI part for a QPushButton.
What did you change? What is not working?

I did change nothing, only added the visible property to the 12220 file.
Now the application starts like I want displaying only the contents from the main ui window (12221), but the QPushButton is not working anymore.
It should show or hide the window like it did before.

The app I'm trying to modify has only 2 ui files, no header or source files at all.
I assume it was created with Qt because among all the plugin dll's there are:

ibgcc_s_dw2-1.dll
mingwm10.dll
QtCore4.dll
QtGui4.dll
QtNetwork4.dll
QtWebKit4.dll
QtXml4.dll
QtXmlPatterns4.dll

If there where source and header files a slot could be added or modified, but that's not the case.

I'm ready to give up on this one, as I'm not a developer except you have an idea what I could do.

Thanks for your patience.

Here are the 2 attached ui files

12220 - 12221

anda_skoa
19th November 2016, 13:47
....... here the answer to a few of your questions

I have a hard time understanding how these different things are related to each other.

On one hand you talk about two windows.
Then you show UI code that hides one label inside one of these windows.
Then you write something about an unrelated button that is not working.



Line 32, 33, 34 in the code below.
It's not the full code of the ui, because it would be to long.

Ok, this hides a label inside on of your windows.



Now the application starts like I want displaying only the contents from the main ui window (12221), but the QPushButton is not working anymore.

How is changing the visibilty of an unrelated label affecting a button somewhere?
Also what does "not working anymore" mean exactly?
Is the button still there? Is it enabled? Is its clicked() signals still connected to a slot? Is the slot being executed?



It should show or hide the window like it did before.

How is hiding/showing a window related to changing on of those window's UI file?



The app I'm trying to modify has only 2 ui files, no header or source files at all.

Well, that is not what you showed in your original posting.
There you had at least the C++ file containing main(), and two headers, one for each window class.
Most likely each of them having a C++ file for their code.



If there where source and header files a slot could be added or modified, but that's not the case.

So the code you had in your first post is from an unrelated program?

Cheers,
_

.Tommy.
19th November 2016, 15:05
....... 1st of all it is still the same program.

When I started this thread I had compiled a project from the 2 ui files and placed all the header and source files into the same directory which contains the ui files, but the modification I made been overridden when I ran the app and did not show, only in Q Creator they did work.

Sorry, that I did not mention that I removed the project files and worked only on the ui files after that.

Anyway, right now the only modification is that I added the visible property to the QFrame class inside the 12222

The QPushButton which is not working anymore is in the 12223 and it is still there and clickable but nothing happens when it is clicked.

That means the new added property had an effect on the button.

If I can get the button to work again I'm done.

Thanks again .......

anda_skoa
19th November 2016, 18:14
When I started this thread I had compiled a project from the 2 ui files and placed all the header and source files into the same directory which contains the ui files, but the modification I made been overridden when I ran the app and did not show, only in Q Creator they did work.

That does not make any sense. Either it works or it doesn't.
Sounds to me like you are starting two different programs.



Sorry, that I did not mention that I removed the project files and worked only on the ui files after that.

Ah, so you don't have any actual program anymore.
How do you "start" that then? Without any code there is no executable, nothing to start.



Anyway, right now the only modification is that I added the visible property to the QFrame class inside the 12222

So yet another unrelated modification compared to the previous posting.
Why do you keep modifying these files instead of first focusing to get it to work again?

There is little point in trying to help you if you keep doing all kinds of unrelated changes everytime you come back.



The QPushButton which is not working anymore is in the 12223 and it is still there and clickable but nothing happens when it is clicked.

Well, if you removed all the code that actually implemented the functionality, then why do you expect anything to work at all?
You can't even start it anymore, right?



If I can get the button to work again I'm done.

You could start by actually having a program to work on.
Add the source and headers back into the project and verify that you can build and run it before attempting any further modifcations to files that are useless stand-alone.

Cheers,
_

.Tommy.
19th November 2016, 20:52
....... it must be my English, that's why there is a misunderstanding I guess.

I do have a working and running application, I'm using it right now to connect to the internet.

I only want to make one change to the user interface.

Without any modification the application starts like this:

12225

With the added property to 12226 in line 32 it starts like this:

12224

Only the QPushButton in 12227 line 521 is not working anymore after the property was added.

12228

anda_skoa
20th November 2016, 11:54
I do have a working and running application, I'm using it right now to connect to the internet.

Can you list the files you have in that project?
I would expect that you have: main.cpp, ExtendFrame.h, ExtendFrame.cpp, ExtendFrame.ui, MiniFrame.h, MiniFrame.cpp, MiniFrame.ui and a ".pro" file.

Make sure all the ".cpp" files are listed in the ".pro" file's SOURCES variable, all ".h" files in the HEADERS variable and all ".ui" files in the FORMS variable



Only the QPushButton in 12227 line 521 is not working anymore after the property was added.

The only thing I can think of is that the code assumes a different state for the other widget's visibilty, but a second click should make it appear.
In that case one could either make sure the initial state as assumed by the code is also "hidden" or changing the code to apply that initial state.

In any case the functionality should be unaffected, but you need to look on how the button is connected.

Cheers,
_