Results 1 to 12 of 12

Thread: Hide QWidget Window on Application Startup

  1. #1
    Join Date
    Nov 2016
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Question Hide QWidget Window on Application Startup

    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:

    Qt Code:
    1. #include "ExtendFrame.h"
    2. #include "MiniFrame.h"
    3. #include "ui_ExtendFrame.h"
    4. #include "ui_MiniFrame.h"
    5. #include <QApplication>
    6. #include <QtGui>
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QApplication a(argc, argv);
    11. miniplugin_bgwidget w;
    12. w.show();
    13.  
    14. miniplugin_bg x;
    15. x.hide();
    16.  
    17. return a.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 

    No changes are applied to the actual ui files.

    Please someone give me hint.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,418
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Hide QWidget Window on Application Startup

    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,
    _

  3. #3
    Join Date
    Nov 2016
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Question Re: Hide QWidget Window on Application Startup

    ....... 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 ...?...

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,418
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Hide QWidget Window on Application Startup

    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,
    _

  5. #5
    Join Date
    Nov 2016
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Question Re: Hide QWidget Window on Application Startup

    ....... 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):

    Qt Code:
    1. <property name="visible">
    2. <bool>false</bool>
    3. </property>
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. <widget class="QPushButton" name="miniplugin_modalExtendApp">
    2. <property name="geometry">
    3. <rect>
    4. <x>153</x>
    5. <y>320</y>
    6. <width>63</width>
    7. <height>20</height>
    8. </rect>
    9. </property>
    10. <property name="minimumSize">
    11. <size>
    12. <width>63</width>
    13. <height>20</height>
    14. </size>
    15. </property>
    16. <property name="maximumSize">
    17. <size>
    18. <width>63</width>
    19. <height>20</height>
    20. </size>
    21. </property>
    22. <property name="focusPolicy">
    23. <enum>Qt::NoFocus</enum>
    24. </property>
    25. <property name="text">
    26. <string/>
    27. </property>
    28. <property name="iconSize">
    29. <size>
    30. <width>24</width>
    31. <height>24</height>
    32. </size>
    33. </property>
    34. <property name="flat">
    35. <bool>true</bool>
    36. </property>
    37. <property name="CLASSID" stdset="0">
    38. <string>F367D78A-0578-FBC4-A89E-65CB0AB3CCEC</string>
    39. </property>
    40. </widget>
    To copy to clipboard, switch view to plain text mode 

    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 ...?...

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,418
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Hide QWidget Window on Application Startup

    Quote Originally Posted by .Tommy. View Post
    ....... 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

    Quote Originally Posted by .Tommy. View Post
    Anyway, I added this property to the ui file (outsite Q Creator):
    Editing the UI code can also be done in QtCreator.

    Quote Originally Posted by .Tommy. View Post
    Qt Code:
    1. <property name="visible">
    2. <bool>false</bool>
    3. </property>
    To copy to clipboard, switch view to plain text mode 
    The visible property of what?

    Quote Originally Posted by .Tommy. View Post
    It works ok except for the QPushButton which is in the other ui file:

    Qt Code:
    1. <widget class="QPushButton" name="miniplugin_modalExtendApp">
    2. <property name="geometry">
    3. <rect>
    4. <x>153</x>
    5. <y>320</y>
    6. <width>63</width>
    7. <height>20</height>
    8. </rect>
    9. </property>
    10. <property name="minimumSize">
    11. <size>
    12. <width>63</width>
    13. <height>20</height>
    14. </size>
    15. </property>
    16. <property name="maximumSize">
    17. <size>
    18. <width>63</width>
    19. <height>20</height>
    20. </size>
    21. </property>
    22. <property name="focusPolicy">
    23. <enum>Qt::NoFocus</enum>
    24. </property>
    25. <property name="text">
    26. <string/>
    27. </property>
    28. <property name="iconSize">
    29. <size>
    30. <width>24</width>
    31. <height>24</height>
    32. </size>
    33. </property>
    34. <property name="flat">
    35. <bool>true</bool>
    36. </property>
    37. <property name="CLASSID" stdset="0">
    38. <string>F367D78A-0578-FBC4-A89E-65CB0AB3CCEC</string>
    39. </property>
    40. </widget>
    To copy to clipboard, switch view to plain text mode 
    Aside from the fixed size this looks like a normal UI part for a QPushButton.
    What did you change? What is not working?

    Quote Originally Posted by .Tommy. View Post
    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,
    _

  7. #7
    Join Date
    Nov 2016
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Hide QWidget Window on Application Startup

    ....... 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 ExtendFrame.ui

    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>miniplugin_bg</class>
    4. <widget class="QWidget" name="miniplugin_bg">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>328</width>
    10. <height>147</height>
    11. </rect>
    12. </property>
    13. <property name="windowTitle">
    14. <string>Mobile Partner</string>
    15. </property>
    16. <property name="styleSheet">
    17. <string notr="true"/>
    18. </property>
    19. <property name="X" stdset="0">
    20. <number>63</number>
    21. </property>
    22. <property name="Y" stdset="0">
    23. <number>337</number>
    24. </property>
    25. <property name="Length" stdset="0">
    26. <number>52</number>
    27. </property>
    28. <widget class="QLabel" name="AppUIPlugin_bglabel">
    29. <property name="enable">
    30. <bool>true</bool>
    31. </property>
    32. <property name="visible">
    33. <bool>false</bool>
    34. </property>
    35. <property name="geometry">
    36. <rect>
    37. <x>0</x>
    38. <y>0</y>
    39. <width>328</width>
    40. <height>147</height>
    41. </rect>
    42. </property>
    43. <property name="minimumSize">
    44. <size>
    45. <width>328</width>
    46. <height>147</height>
    47. </size>
    48. </property>
    49. <property name="maximumSize">
    50. <size>
    51. <width>328</width>
    52. <height>147</height>
    53. </size>
    54. </property>
    55. <property name="text">
    56. <string/>
    57. </property>
    58. </widget>
    59. </widget>
    60. <resources/>
    61. <connections/>
    62. </ui>
    To copy to clipboard, switch view to plain text mode 

    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 ExtendFrame.ui file.
    Now the application starts like I want displaying only the contents from the main ui window (MiniFrame.ui), 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

    ExtendFrame.ui - MiniFrame.ui

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,418
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Hide QWidget Window on Application Startup

    Quote Originally Posted by .Tommy. View Post
    ....... 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.

    Quote Originally Posted by .Tommy. View Post
    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.

    Quote Originally Posted by .Tommy. View Post
    Now the application starts like I want displaying only the contents from the main ui window (MiniFrame.ui), 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?

    Quote Originally Posted by .Tommy. View Post
    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?

    Quote Originally Posted by .Tommy. View Post
    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.

    Quote Originally Posted by .Tommy. View Post
    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,
    _

  9. #9
    Join Date
    Nov 2016
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Hide QWidget Window on Application Startup

    ....... 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 ExtendFrame.ui

    The QPushButton which is not working anymore is in the MiniFrame.ui 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 .......

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,418
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Hide QWidget Window on Application Startup

    Quote Originally Posted by .Tommy. View Post
    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.

    Quote Originally Posted by .Tommy. View Post
    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.

    Quote Originally Posted by .Tommy. View Post
    Anyway, right now the only modification is that I added the visible property to the QFrame class inside the ExtendFrame.ui
    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.

    Quote Originally Posted by .Tommy. View Post
    The QPushButton which is not working anymore is in the MiniFrame.ui 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?

    Quote Originally Posted by .Tommy. View Post
    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,
    _

  11. #11
    Join Date
    Nov 2016
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Hide QWidget Window on Application Startup

    ....... 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:

    Screenshot (1).jpg

    With the added property to ExtendFrame.ui in line 32 it starts like this:

    Screenshot (2).jpg

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

    Screenshot (3).jpg
    Last edited by .Tommy.; 19th November 2016 at 20:01.

  12. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,418
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Hide QWidget Window on Application Startup

    Quote Originally Posted by .Tommy. View Post
    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

    Quote Originally Posted by .Tommy. View Post
    Only the QPushButton in MiniFrame.ui 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,
    _

Similar Threads

  1. Load custom plugins after application startup.
    By rwhartzell in forum Newbie
    Replies: 6
    Last Post: 29th August 2015, 18:36
  2. Replies: 0
    Last Post: 15th October 2013, 09:32
  3. Launch Qt Server Application at startup ?
    By JcPep in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 2nd May 2013, 16:24
  4. Qt application loads tons of dll's ONLY on OS startup
    By tomrider in forum Qt Programming
    Replies: 5
    Last Post: 12th May 2011, 09:52
  5. Showing a dialog at application startup
    By PaladinOfKaos in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2008, 20:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.