0

I'm totally new to Qt framework. What I'm trying to get is to hide all widgets when I start my program, so when the MainWindow is opened. I'm not coding it. I was just editing the program in "Design" editor. I was looking for an option where I can just set widget hidden by default, but without any success.

Thank you for your help.

huysentruitw
  • 27,376
  • 9
  • 90
  • 133
Dawid Zbiński
  • 5,521
  • 8
  • 43
  • 70
  • I mean I can do some coding if it's needed. I just didn't code the program until now, because I'm just adjusting the GUI. I know it would be better to have it coded, but I'm really new to whole Qt Framework, so for now I'm studying. I just wanted to know how to do that and help others who have that problem. – Dawid Zbiński Jan 15 '16 at 11:20

1 Answers1

1

Would you like to make MainWindow invisible or just hide all widgets from MainWindow?

First:

hide();

Second:

//after setup ui
    foreach( QWidget * child, findChildren< QWidget * >() ) 
    {
        child->hide();
    }
  • I want to hide all widgets with names widget* after the MainWindow has been opened. – Dawid Zbiński Jan 15 '16 at 13:38
  • Ok, so you can use something like QList children = findChildren ( QRegExp( "widget*", Qt::CaseSensitive, Wildcard ) ); to find them. foreach to iterate, hide() to hide them. You can do that in constructor after setup ui or in protected member showEvent –  Jan 15 '16 at 13:46
  • Alright. Thanks a lot. I'll try to implement the code ina while. If something goes wrong I will let you know. Acutally.. I see you're pretty good in Qt :) I have one more question. Can you explain what are the particular files for? I mean. I know what .ui files are for. But where to put other codes? main.cpp or mainwindows.cpp? Because I guess I don't need to manipulate with mainwindow.h header too much. – Dawid Zbiński Jan 15 '16 at 13:52
  • 1
    A little out of subject but I'l try to explain. Anyway sorry for my english, it's not my native language. In main.cpp you create QApplication object and main form class. mainwindow.h - header of that form. there are you declare class, signals, slots, methods, members, etc. mainwindow.cpp - for implementation of that methods. ui - file, described how form looks. From it wil be generated ui_mainwindow.h. –  Jan 15 '16 at 14:03
  • Your english is fine. I'm not native english speaker too, so I'm fully satisified with yours. And yeah. I understand the concept of these files and interaction between them. Thank you. There is not so many tutorials or e-books for Qt for beginners so I'm a bit disapointed and cannot learn so much by myself. Otherwise, thanks a lot once again. – Dawid Zbiński Jan 15 '16 at 14:11