GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Jul 29, 2014 10:44 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Unable to set layout in homogenous grid !
PostPosted: Sat Mar 01, 2014 2:15 am 
Offline
Familiar Face

Joined: Fri Jan 10, 2014 2:29 pm
Posts: 21
I have a grid with two rows in it, I wanted the content in row one to be scaleable as I change the size of window or grid.
So I opted for homogenous row for grid but as there is change of size in row 1 row 2 size also changes what should I do ?

Code:
#include <stdio.h>
#include <gtk/gtk.h>

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

   GtkWidget *window;
   GtkWidget *grid;
   GtkWidget *halign;
   GtkWidget *button;
   GtkWidget *textpad;

   gtk_init(&argc,&argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    button = gtk_button_new_with_label("hey");
    halign = gtk_alignment_new(0,0,0,0);
    grid = gtk_grid_new();
    textpad = gtk_text_view_new();
    gtk_grid_set_column_homogeneous(GTK_GRID(grid),TRUE);
    gtk_grid_set_row_homogeneous(GTK_GRID(grid),TRUE);
    gtk_widget_set_size_request(textpad,230,150);

    gtk_container_add(GTK_CONTAINER(halign),button);
    gtk_grid_attach(GTK_GRID(grid),textpad,0,0,1,1);
    gtk_grid_attach(GTK_GRID(grid),halign,0,1,1,1);
    gtk_container_add(GTK_CONTAINER(window),grid);

    gtk_widget_show_all(window);
    g_signal_connect(G_OBJECT(window),"destroy",G_CALLBACK(gtk_main_quit),NULL);
    gtk_main();
}

Attachment:
screenCap.png
screenCap.png [ 7.25 KiB | Viewed 237 times ]


Last edited by zerohour on Sat Mar 01, 2014 5:18 pm, edited 1 time in total.
Too much blank space/ image unnecessarily large


Top
 Profile  
 
 Post subject: Re: Unable to set layout in homogenous grid !
PostPosted: Sun Mar 02, 2014 4:51 pm 
Offline
GTK+ Geek

Joined: Fri Sep 04, 2009 6:53 am
Posts: 68
The word homogenous means "of the same or a similar kind or nature".
Setting gtk_grid_set_column_homogeneous and gtk_grid_set_row_homogeneous to "True" will reserved the same size for both widgets.
Also set the expand property of the widget that you want to expand to "True" (https://developer.gnome.org/gtk3/3.6/Gt ... et--expand).

In python3 and gtk3 you should use something like this:

Code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import gi
gi.require_version("Gtk","3.0")
from gi.repository import Gtk

class Window(Gtk.Window):

    def __init__(self):

        super(Window,self).__init__()

        self.connect("destroy",Gtk.main_quit)

        grid=Gtk.Grid()
        self.add(grid)

        button1=Gtk.Button("button1")
        grid.attach(button1,0,0,2,1)
        button1.set_property("expand",True)

        button2=Gtk.Button("button2")
        grid.attach(button2,1,1,1,1)

        self.show_all()


window=Window()
Gtk.main()


Top
 Profile  
 
 Post subject: Re: Unable to set layout in homogenous grid !
PostPosted: Sun Mar 02, 2014 6:01 pm 
Offline
Familiar Face

Joined: Fri Jan 10, 2014 2:29 pm
Posts: 21
Thanks a Lot Fella :D Expand Works


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 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