GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Oct 01, 2014 4:17 pm

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: [solved] Hiding a Widget and Automatically Resizing Parent
PostPosted: Sat Mar 22, 2008 4:56 pm 
Offline
Familiar Face

Joined: Sat Mar 22, 2008 4:47 pm
Posts: 6
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:
#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.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 24, 2008 2:30 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
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.

Image

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 24, 2008 3:43 pm 
Offline
Familiar Face

Joined: Sat Mar 22, 2008 4:47 pm
Posts: 6
Perfect! Thank you Micah!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 24, 2008 3:59 pm 
Offline
Familiar Face

Joined: Sat Mar 22, 2008 4:47 pm
Posts: 6
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?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 24, 2008 4:14 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Set the "expand" property of the expander to FALSE.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 24, 2008 4:58 pm 
Offline
Familiar Face

Joined: Sat Mar 22, 2008 4:47 pm
Posts: 6
I did...no difference. :(


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 24, 2008 6:02 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Are you using Glade or pure GTK+. Can you post your code that builds the interface?

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 24, 2008 9:17 pm 
Offline
Familiar Face

Joined: Sat Mar 22, 2008 4:47 pm
Posts: 6
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:
<?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>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 24, 2008 10:04 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
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/ ... art-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.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 25, 2008 2:45 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
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).

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 25, 2008 5:29 pm 
Offline
Familiar Face

Joined: Sat Mar 22, 2008 4:47 pm
Posts: 6
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!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group