IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

GTK+ avec C & C++ Discussion :

position dans des gtk_table


Sujet :

GTK+ avec C & C++

  1. #1
    Membre régulier
    Homme Profil pro
    chercheur
    Inscrit en
    Décembre 2012
    Messages
    195
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : chercheur

    Informations forums :
    Inscription : Décembre 2012
    Messages : 195
    Points : 84
    Points
    84
    Par défaut position dans des gtk_table
    Bonjour,

    L'utilisation des gtk_tables m'est indispensable, mais continue à me poser des problèmes. Après plusieurs jours à me battre avec mon code, je crois que j'arrive bien à identifier ce que je ne comprends pas. Et j'ai construit un code-exemple qui montre ce qui ne va pas, ou ce que je n'ai pas compris.

    Je m'explique: Ma fenêtre principale contiens une box verticale qui - elle - contient deux éléments : un gtk_frame et un gtk_table.

    Le code est le suivant:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    /* travail sur les tables */
    #include <stdlib.h>
    #include <gtk/gtk.h>
     
    int main (int argc, char *argv[])
    {
        GtkWidget *win=NULL;
        GtkWidget *pTable=NULL;
        GtkWidget *pTable_titre=NULL;
        GtkWidget *pTable_bandeau=NULL;
        GtkWidget *pTable_liste=NULL;
        GtkWidget *boxv=NULL;
        GtkWidget *boxv2=NULL;
        GtkWidget *label[300];
        GtkWidget *label_titre=NULL;
        GtkWidget *titre_principal=NULL;
        GtkWidget *frame0=NULL;
        GtkWidget *frame1=NULL;
        GtkWidget *frame2=NULL;
        GtkWidget *barre_defilement=NULL;
        char tmp[500];
        int i;
        /* Initialize GTK+ */
        gtk_init (&argc, &argv);
        /* Creating the main window */
        win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_container_set_border_width (GTK_CONTAINER (win), 8);
        gtk_window_set_title (GTK_WINDOW (win), "testing table..");
        gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
        gtk_window_set_default_size(GTK_WINDOW(win), 750, 500);
        g_signal_connect(win, "destroy", G_CALLBACK(gtk_main_quit), NULL);
        /* creation d'une box verticale */
        boxv=gtk_vbox_new(FALSE, 0);
        /* creation d'une autre box verticale */
        boxv2=gtk_vbox_new(FALSE, 0);
        /* creation des labels  et insertion dans la boxv*/
        for (i=0;i<300;i++)
        {
            (void)sprintf(tmp,"texte%d",i);
            label[i]=gtk_label_new(tmp);
            gtk_box_pack_start(GTK_BOX(boxv),label[i], FALSE, FALSE, 5);
        }
        /* création de la scolling window correspondante */
        barre_defilement=gtk_scrolled_window_new(NULL, NULL);
        /* on ne veux que la barre verticale - if needed */
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(barre_defilement), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
        /* on ne veux pas de bord autour */
        gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(barre_defilement), GTK_SHADOW_NONE);
        /* on met la barre à gauche */
        gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(barre_defilement), GTK_CORNER_BOTTOM_RIGHT);
        /* on met la boxv la scrolling window */
        gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(barre_defilement), boxv);
        /* creation du titre principal */
        (void)sprintf(tmp,"titre Principal");
        titre_principal=gtk_label_new(tmp);
        /* creation de la table titre */
        pTable_titre=gtk_table_new((guint)3,(guint)20,FALSE);
        /* creation du frame 0 */
        frame0=gtk_frame_new(NULL);
        gtk_frame_set_shadow_type(GTK_FRAME(frame0), GTK_SHADOW_ETCHED_OUT);
        /* on met le titre dans la table et la table dans le frame */
        gtk_table_attach(GTK_TABLE(pTable_titre), titre_principal, 0,20,0,3,GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,0,0 );
        gtk_container_add(GTK_CONTAINER(frame0), GTK_WIDGET(pTable_titre));
        /* creation d'un titre "bandeau" */
        (void)sprintf(tmp,"bandeau du titre");
        label_titre=gtk_label_new(tmp);
        /* creation de la table liste */
        pTable_liste=gtk_table_new((guint)18,(guint)4,FALSE);
        /* création de la table bandeau */
        pTable_bandeau=gtk_table_new((guint)2,(guint)20,FALSE);
        /* on met le bandeau dedans */
        gtk_table_attach(GTK_TABLE(pTable_bandeau), label_titre, 0,20,0,2,GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,0,0 );
        /* on met la boxv et sa barre de défilement dedans */
        gtk_table_attach(GTK_TABLE(pTable_liste), barre_defilement, 0,4,0,18,GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,0,0 );
        /*création de la table principale mise des widgets dedans */
        pTable=gtk_table_new((guint)20,(guint)20,FALSE);
        /* Creation de deux frames */
        frame1=gtk_frame_new(NULL);
        gtk_frame_set_shadow_type(GTK_FRAME(frame1), GTK_SHADOW_ETCHED_OUT);
        frame2=gtk_frame_new(NULL);
        gtk_frame_set_shadow_type(GTK_FRAME(frame2), GTK_SHADOW_ETCHED_OUT);
        /* on met la table bandeau dans le 1er frame et la table liste dans la seconde */
        gtk_container_add(GTK_CONTAINER(frame1), GTK_WIDGET(pTable_bandeau));
        gtk_container_add(GTK_CONTAINER(frame2), GTK_WIDGET(pTable_liste));
        /* on met les frames dans la table */
        gtk_table_attach(GTK_TABLE(pTable), frame1, 0,20,0,2,GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,0,0 );
        gtk_table_attach(GTK_TABLE(pTable), frame2, 0,4,2,20,GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,0,0 );
        /* On met tout dans la box verticale v2 */
        gtk_box_pack_start(GTK_BOX(boxv2),frame0, FALSE, FALSE, 5);
        gtk_box_pack_start(GTK_BOX(boxv2),pTable, FALSE, FALSE, 5);
        /* on ajoute la table dans la fenetre */
        gtk_container_add (GTK_CONTAINER (win), boxv2);
        /* Enter the main loop */
        gtk_widget_show_all (win);
        gtk_main();
        return 0;
    }
    La position du frame a gauche est complètement riquiqui, et ne correspond en rien aux emplacements que je lui ai assignés.

    Si je vire la gtk_frame en haut, c'est à dire si je remplace les lignes 88 à 92 par :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     /* On met tout dans la box verticale v2 */
        /* gtk_box_pack_start(GTK_BOX(boxv2),frame0, FALSE, FALSE, 5);
        gtk_box_pack_start(GTK_BOX(boxv2),pTable, FALSE, FALSE, 5); */
        /* on ajoute la table dans la fenetre */
            /* gtk_container_add (GTK_CONTAINER (win), boxv2); */
        gtk_container_add (GTK_CONTAINER (win), pTable);
    c'est à dire, en clair, si je n'ai que la gtk_table dans ma fenètre, alors tout marche très bien.

    C'est une énigme totale pour moi. Comment ce fait t'il que les positions dans une gtk_table soient modifiées si cette gtk_table cohabite avec un autre élément dans une box ?

    Je suis à court d'idée, et toute aide sur ce point est la bienvenue !

    D'avance merci pour votre temps,

    Cordialement, Eric.

  2. #2
    Membre confirmé
    Profil pro
    Retraité
    Inscrit en
    Novembre 2009
    Messages
    329
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Novembre 2009
    Messages : 329
    Points : 606
    Points
    606
    Par défaut
    C'est l'appel à gtk_box_pack_start() qui gouverne quel espace peut être occupé par le widget contenu dans la boite.
    Si dans la ligne 90 qui sert à insérer la table dans la boite, tu remplace FALSE par TRUE (les arguments expand et fill), l'espace occupé par la table peut s'agrandir et le résultat ressemble beaucoup plus à ce que tu souhaite.
    GraceGTK: a plotting tool at https://sourceforge.net/projects/gracegtk

  3. #3
    Membre régulier
    Homme Profil pro
    chercheur
    Inscrit en
    Décembre 2012
    Messages
    195
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : chercheur

    Informations forums :
    Inscription : Décembre 2012
    Messages : 195
    Points : 84
    Points
    84
    Par défaut
    Citation Envoyé par pvincent Voir le message
    C'est l'appel à gtk_box_pack_start() qui gouverne quel espace peut être occupé par le widget contenu dans la boite.
    Si dans la ligne 90 qui sert à insérer la table dans la boite, tu remplace FALSE par TRUE (les arguments expand et fill), l'espace occupé par la table peut s'agrandir et le résultat ressemble beaucoup plus à ce que tu souhaite.
    Ok, merci. Ca semble effectivement répondre à ma question. Il va falloir que je travaille encore sur ca...

    Encore merci,

    Eric.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Des lignes horizontales et verticales dans des gtk_tables
    Par eric1708 dans le forum GTK+ avec C & C++
    Réponses: 15
    Dernier message: 03/10/2013, 08h51
  2. Réponses: 4
    Dernier message: 08/09/2011, 18h13
  3. Réponses: 1
    Dernier message: 08/09/2011, 17h50
  4. Position du texte dans des cellules fusionnées
    Par argal dans le forum Excel
    Réponses: 3
    Dernier message: 12/08/2008, 17h24
  5. Réponses: 3
    Dernier message: 29/05/2008, 11h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo