GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[solved] Hiding a Widget and Automatically Resizing Parent

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
Colorblind Pilot
Familiar Face


Joined: 22 Mar 2008
Posts: 6

PostPosted: Sat Mar 22, 2008 4:56 pm    Post subject: [solved] Hiding a Widget and Automatically Resizing Parent Reply with quote

Hi,

I have a window with a vbox in it. The vbox has 5 non-homogenous slices. When the program starts I want to initially hide the 4th slice and have the vbox collapse so that the user wouldn't know its there. Then when they click the "More Details" button on the menubar, that 4th slice appears, pushing everything around it outward.

My problem is that when I hide the widget in the beginning, it leaves a big space for it. How can I get it to collapse? Here is my code:

Code: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

#include <gtk/gtk.h>
#include <glade/glade.h>

int main(int argc, char *argv[])
{

    GladeXML *gxml;
        GtkWidget *window;
    GtkWidget *details;
   
    gtk_init (&argc, &argv);

        gxml = glade_xml_new ("yaarbox.glade", NULL, NULL);
        window = glade_xml_get_widget (gxml, "window");
        details = glade_xml_get_widget(gxml, "frame_detail");
   
    gtk_widget_show(window);
        gtk_widget_hide(details);

    gtk_main ();

    return 0;
}


Obviously, I've simplified it quite a bit/removed all the callbacks. Every widget in the vbox is set to expand: no. I'm sure I'm doing something stupid wrong (this is my first foray into GTK+ programming).

I hope someone can help!


Last edited by Colorblind Pilot on Tue Mar 25, 2008 5:30 pm; edited 1 time in total
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 413
Location: Portland, OR USA

PostPosted: Mon Mar 24, 2008 2:30 pm    Post subject: Reply with quote

Although not quite the answer to your exact question, you may want to instead use a GtkExpander packed into the vbox to achieve this "More Details" functionality.

This is how it's typically done in a lot of GTK applications. You may be familiar with this in things like the GNOME "Search for Files" dialog. You click "Show more options" which contains widgets for additional search options. This is a GtkExpander.

Back to top
Colorblind Pilot
Familiar Face


Joined: 22 Mar 2008
Posts: 6

PostPosted: Mon Mar 24, 2008 3:43 pm    Post subject: Reply with quote

Perfect! Thank you Micah!
Back to top
Colorblind Pilot
Familiar Face


Joined: 22 Mar 2008
Posts: 6

PostPosted: Mon Mar 24, 2008 3:59 pm    Post subject: Reply with quote

One problem, though. When I click the expander, it works perfectly to open up the options. But when I click the expander again to collapse it, it leaves a huge unslightly space where it used to be. Is there any way to get rid of that?
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 413
Location: Portland, OR USA

PostPosted: Mon Mar 24, 2008 4:14 pm    Post subject: Reply with quote

Set the "expand" property of the expander to FALSE.
Back to top
Colorblind Pilot
Familiar Face


Joined: 22 Mar 2008
Posts: 6

PostPosted: Mon Mar 24, 2008 4:58 pm    Post subject: Reply with quote

I did...no difference. :(
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 413
Location: Portland, OR USA

PostPosted: Mon Mar 24, 2008 6:02 pm    Post subject: Reply with quote

Are you using Glade or pure GTK+. Can you post your code that builds the interface?
Back to top
Colorblind Pilot
Familiar Face


Joined: 22 Mar 2008
Posts: 6

PostPosted: Mon Mar 24, 2008 9:17 pm    Post subject: Reply with quote

I'm using glade. Here's my .glade file. There's only one GtkExpander item; I removed a lot of the children from the file or else it was too big...let me know if I took too much out. Thanks for your help.

Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

<?xml version="1.0" encoding="UTF-8" standalone="no"?><?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.0 on Mon Mar 24 13:13:49 2008 -->
<glade-interface>
  <widget class="GtkWindow" id="window">
    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
    <property name="title" translatable="yes">NBreathe - March 22, 2008 Build</property>
    <property name="window_position">GTK_WIN_POS_CENTER</property>
    <signal name="destroy" handler="on_window_destroy"/>
    <child>
      <widget class="GtkVBox" id="vbox1">
        <property name="visible">True</property>
        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
        <child>
          <widget class="GtkMenuBar" id="menubar1">
            <property name="visible">True</property>
            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
          ...children removed...
          </widget>
          <packing>
            <property name="expand">False</property>
          </packing>
        </child>
        <child>
          <widget class="GtkImage" id="logo">
            ...children removed...
          </widget>
          <packing>
            <property name="expand">False</property>
            <property name="position">2</property>
          </packing>
        </child>
        <child>
          <widget class="GtkHBox" id="hbox1">
            <property name="visible">True</property>
            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
            ...children removed...
          </widget>
          <packing>
            <property name="expand">False</property>
            <property name="padding">20</property>
            <property name="position">3</property>
          </packing>
        </child>
        <child>
          <widget class="GtkAlignment" id="alignment_execute">
            <property name="visible">True</property>
            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
            <property name="xscale">0</property>
            <property name="yscale">0</property>
            <child>
              <widget class="GtkButton" id="button_execute">
                ...removed...
              </widget>
            </child>
          </widget>
          <packing>
            <property name="position">4</property>
          </packing>
        </child>
        <child>
          <widget class="GtkExpander" id="expander_details">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
            <signal name="activate" handler="on_expander_details_activate"/>
            <child>
              <widget class="GtkFrame" id="frame_detail">
                <property name="visible">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                <property name="border_width">4</property>
                <property name="label_xalign">0</property>
                <property name="shadow_type">GTK_SHADOW_NONE</property>
                <child>
                  <widget class="GtkHBox" id="hbox2">
                    <property name="visible">True</property>
                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                    <child>
                        ...removed...
                    </child>
                  </widget>
                </child>
                <child>
                     ...removed...
                </child>
              </widget>
            </child>
            <child>
              <widget class="GtkLabel" id="expand_show_advanced_details">
                <property name="visible">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                <property name="label" translatable="yes">Show Advanced Details</property>
              </widget>
              <packing>
                <property name="type">label_item</property>
              </packing>
            </child>
          </widget>
          <packing>
            <property name="expand">False</property>
            <property name="position">5</property>
          </packing>
        </child>
        <child>
          <widget class="GtkStatusbar" id="statusbar">
            <property name="visible">True</property>
            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
            <property name="border_width">1</property>
            <property name="spacing">2</property>
          </widget>
          <packing>
            <property name="expand">False</property>
            <property name="pack_type">GTK_PACK_END</property>
            <property name="position">1</property>
          </packing>
        </child>
      </widget>
    </child>
  </widget>
</glade-interface>
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 413
Location: Portland, OR USA

PostPosted: Mon Mar 24, 2008 10:04 pm    Post subject: Reply with quote

Can't use that. you can email me your glade file at: email at micahcarrick dot com

I explain how packing properties work in Glade 3 in my tutorial which may help: http://www.micahcarrick.com/12-24-2007/gtk-glade-tutorial-part-1.html

Let's assume that your GtkVBox has 3 rows. A menu bar in the top, a text view in the middle, and an expander in the bottom. The menu bar and expander would both have expand = fill = false. The text view (or scrolled window) would have it's expand = fill = true. The vbox would also have homogenous = false.
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 413
Location: Portland, OR USA

PostPosted: Tue Mar 25, 2008 2:45 pm    Post subject: Reply with quote

Looking at the Glade file you sent, I'm not entirely sure HOW you want it to resize.

There's a couple of ways to look at this. What I would typically do, is decide if the UI should be user-resizable. Currently, the main window is resizable. It looks as though you have set it up so that the only "area" that will resize with the window being resized is the GtkAlignment with the GtkButton.

With a dialog window like this, there isn't much need for it to be resizable. Increasing the size of this dialog does not show any more functionality. What I might do, is make the main GtkWindow NOT resizable and all those widgets in the GtkVBox get expand=false. Doing this would mean the entire GtkWindow will "snap" open when the GtkExpander is clicked.

However, when you're using the minimal sizes of these widgets, you should allow for some nice padding and borders. I highly reccomend you follow the suggestions in the GNOME Human Interface Guidelines (Google search for GNOME HIG).
Back to top
Colorblind Pilot
Familiar Face


Joined: 22 Mar 2008
Posts: 6

PostPosted: Tue Mar 25, 2008 5:29 pm    Post subject: Reply with quote

Ah! That did the trick! Setting the window to resizable: no make it snap back when I unexpanded the GtkExpander. Thank you Micah, you're the man!!!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP