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 :

gtk treeview scroll à la ligne selectionnée


Sujet :

GTK+ avec C & C++

  1. #1
    Nouveau membre du Club
    Inscrit en
    Décembre 2006
    Messages
    31
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 31
    Points : 30
    Points
    30
    Par défaut gtk treeview scroll à la ligne selectionnée
    Bonjour,

    J'utilise Gtk en C et je sais comment sélectionner une ligne spécifique dans un GTK_TREE_MODEL (voir le code)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    void Select(GtkTreeIter* treeIter)
    {
     	GtkTreePath* treePath = ::gtk_tree_model_get_path(GTK_TREE_MODEL(GetStore()), treeIter);
     
    	::gtk_tree_view_collapse_all(GTK_TREE_VIEW(GetView()));
    	::gtk_tree_view_expand_to_path(GTK_TREE_VIEW(GetView()), treePath);
    	::gtk_tree_view_set_cursor(GTK_TREE_VIEW(GetView()), treePath, 0, 0);
    	//DIG ::gtk_tree_view_scroll_to_point(GTK_TREE_VIEW(GetView()), 100, 100);
     
    	::gtk_tree_path_free(treePath);
    }
    Malheureusement, cette ligne est en dehors de la fenêtre d'affichage.
    Mon souhait est de mettre cette ligne au milieu de la fenêtre.
    Avez vous une solution ?

    Merci beaucoup,
    Gelu

  2. #2
    Expert confirmé
    Avatar de gerald3d
    Homme Profil pro
    Conducteur de train
    Inscrit en
    Février 2008
    Messages
    2 291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Conducteur de train
    Secteur : Transports

    Informations forums :
    Inscription : Février 2008
    Messages : 2 291
    Points : 4 941
    Points
    4 941
    Billets dans le blog
    5
    Par défaut
    Qui appelle void Select(GtkTreeIter* treeIter); ?

  3. #3
    Nouveau membre du Club
    Inscrit en
    Décembre 2006
    Messages
    31
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 31
    Points : 30
    Points
    30
    Par défaut
    Salut,

    Mon programme est assez complexe.
    J'ai une liste qui contient tous les itérateurs sur le tree.
    Ainsi je peux appeler Select en utilisant l'itérateur correspondant.

    A+G

  4. #4
    Expert confirmé
    Avatar de gerald3d
    Homme Profil pro
    Conducteur de train
    Inscrit en
    Février 2008
    Messages
    2 291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Conducteur de train
    Secteur : Transports

    Informations forums :
    Inscription : Février 2008
    Messages : 2 291
    Points : 4 941
    Points
    4 941
    Billets dans le blog
    5
    Par défaut
    Ne voyant pas ton code je ne préjuge de rien mais attention tout de même. Les GtkIter sont assez volatiles. Ils peuvent ne plus pointer au même endroit dés lors que le GtkTreeModel (ou autre) est modifié.

  5. #5
    Membre confirmé Avatar de Gaulouis
    Homme Profil pro
    Administrateur de base de données
    Inscrit en
    Octobre 2015
    Messages
    252
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2015
    Messages : 252
    Points : 476
    Points
    476
    Par défaut
    Bonsoir,

    La fonction gtk_tree_view_scroll_to_cell semble répondre à ton besoin.

    @+

  6. #6
    Nouveau membre du Club
    Inscrit en
    Décembre 2006
    Messages
    31
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 31
    Points : 30
    Points
    30
    Par défaut
    Bonsoir,

    Deux fonctions pourraient faire l'affaire

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    void
    gtk_tree_view_scroll_to_point (GtkTreeView *tree_view,
                                   gint tree_x,
                                   gint tree_y);
    et

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    void
    gtk_tree_view_scroll_to_cell (GtkTreeView *tree_view,
                                  GtkTreePath *path,
                                  GtkTreeViewColumn *column,
                                  gboolean use_align,
                                  gfloat row_align,
                                  gfloat col_align);
    mais, comment calculer les paramètres d'entrée

    par exemple comment calculer tree_x, tree_y pour gtk_tree_view_scroll_to_point

    Merci,
    Gelu

  7. #7
    Membre confirmé Avatar de Gaulouis
    Homme Profil pro
    Administrateur de base de données
    Inscrit en
    Octobre 2015
    Messages
    252
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2015
    Messages : 252
    Points : 476
    Points
    476
    Par défaut
    comment calculer tree_x, tree_y pour gtk_tree_view_scroll_to_point
    Regarde comment gtk_tree_view_scroll_to_cell calcule les paramètres (dest_x, dest_y) pour gtk_tree_view_scroll_to_point.
    Il y a deux fonctions importante gtk_tree_view_get_background_area et gtk_tree_view_get_visible_rect.

    Je ne peux pas entrée dans les détail, mais le calcule s'appuie sur GtkAdjustment, GtkAllocation, TREE_VIEW_HEADER_HEIGHT, et gtk_tree_view_get_cell_area

    Nom : Panoramix.gif
Affichages : 406
Taille : 12,4 Ko Souhaite-tu positionner la ligne sélectionné de manière à afficher les n ligne précédente?

    Comme ce-ci par exemple:
    Nom : alpidor.png
Affichages : 425
Taille : 12,3 Ko

  8. #8
    Nouveau membre du Club
    Inscrit en
    Décembre 2006
    Messages
    31
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 31
    Points : 30
    Points
    30
    Par défaut
    Salut,

    Mon arbre est assez complexe et je veux sélectionner dynamiquement un élément.
    Ca, ça marche.

    L’inconvénient est que la position sélectionné n'est pas dans le TREE_VIEW (idéal serait d'arriver au milieu de la fenêtre ou comme dans ton cas).
    Alors, comment la scroller ?

    J'ai essayé plusieur méthodes mais sans succès
    Par exemple

    GdkRectangle rect;
    ::gtk_tree_view_get_cell_area (GTK_TREE_VIEW(GetView()),
    treePath,
    0,
    &rect);
    ::gtk_tree_view_scroll_to_point(GTK_TREE_VIEW(GetView()), 0, rect.y + 3*rect.height);

    Merci,
    Gelu

  9. #9
    Membre confirmé Avatar de Gaulouis
    Homme Profil pro
    Administrateur de base de données
    Inscrit en
    Octobre 2015
    Messages
    252
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2015
    Messages : 252
    Points : 476
    Points
    476
    Par défaut
    J'ai essayé plusieurs méthodes mais sans succès
    Qu'elle est le comportement que tu attendais et le fonctionnement obtenue avec gtk_tree_view_scroll_to_cell ?

    Peux-tu poster un code minimal et fonctionnel qui illustre ton problème. Exemple

    Bien à toi,

    PS: Pourquoi utilises-tu la résolution de scope "::" pour utiliser l'API C de Gtk en C++ ?

  10. #10
    Nouveau membre du Club
    Inscrit en
    Décembre 2006
    Messages
    31
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 31
    Points : 30
    Points
    30
    Par défaut
    Bonjour,

    Je reprends mon code :

    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
     
    void Select(GtkTreeIter* treeIter)
    {
        GtkTreePath*	treePath	= ::gtk_tree_model_get_path(GTK_TREE_MODEL(GetStore()), treeIter);
        GtkTreeView*	treeView	= GTK_TREE_VIEW(GetView());
     
        ::gtk_tree_view_collapse_all(treeView);
        ::gtk_tree_view_expand_to_path(treeView, treePath);
        ::gtk_tree_view_set_cursor(treeView, treePath, 0, 0);
     
        GdkWindow*   wnd =  gtk_tree_view_get_bin_window(treeView);
        ::gdk_window_process_updates (wnd, TRUE);
     
        ::gtk_tree_path_free(treePath);
    }
    Mon code est assez complexe.
    L'essentiel est que :

    1. mon arbre est situé dans une fenêtre créée avec
      Code : Sélectionner tout - Visualiser dans une fenêtre à part
      1
      2
      3
       
         myTopWidget	= ::gtk_scrolled_window_new(NULL, NULL);
         ::gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(myTopWidget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    2. J'ai une autre fenêtre qui appelle la fonction Select (voir plus haut)
    3. Dans la fonction Select, qui a comme paramètre GtkTreeIter* treeIter, j'exécute les opérations suivantes
      • L'arbre est collapsé
      • L'arbre est expansé à partir de l'itérateur choisi
      • Le curseur dans l'arbre est mis sur l'itérateur choisi


    Quand je debug pas à pas, tout fonctionne bien. Je vois que toutes les opérations sont exécutées comme prévu.

    Mais, après avoir quitté la fonction Select (il faut dire que la pile des appels est très complexe), le système, prend la liberté de placer toujours dans le haut de la fenêtre l'ancien élément qui était déjà là.

    Merci,
    Gelu

  11. #11
    Membre confirmé Avatar de Gaulouis
    Homme Profil pro
    Administrateur de base de données
    Inscrit en
    Octobre 2015
    Messages
    252
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : Enseignement

    Informations forums :
    Inscription : Octobre 2015
    Messages : 252
    Points : 476
    Points
    476
    Par défaut
    Citation Envoyé par gaulouis
    Peux-tu poster un code minimal et fonctionnel qui illustre ton problème. Exemple
    Citation Envoyé par alpidor Voir le message
    Mon code est assez complexe.
    Tu sous-entend quoi ? Qu'on est trop bête pour comprendre ton code ? Que tu es trop fainéant pour isoler le problème ?
    Citation Envoyé par alpidor Voir le message
    L'essentiel est que :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    myTopWidget	= ::gtk_scrolled_window_new(NULL, NULL);
       ::gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(myTopWidget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

    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
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    #include <config.h>
    #include <gtk/gtk.h>
     
    #include <glib/gi18n.h>
     
     
     
    struct _App {
        GtkTreeModel *tree_model;
        GtkWidget    *tree_view;
    };
    static struct _App app = {NULL, NULL};
     
     
    #if 1
     
    #include "gtx-sidebar.h"
    enum
    {
      COL_NAME = 0, // remove COL_NAME
      COL_LABEL,
      COL_WEIGHT_SET,
      COL_WEIGHT,
      COL_STOCK,
      COL_STOCK_VISIBLE,
      NUM_COLS
    } ;
     
     
    static GtkTreeModel *
    create_and_fill_model (void)
    {
      GtkTreeStore  *treestore;
      GtkTreeIter    toplevel, child;
     
      treestore = gtk_tree_store_new(NUM_COLS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INT, G_TYPE_STRING, G_TYPE_BOOLEAN);
     
     
      /* Append a top level row and leave it empty */
      gtk_tree_store_append(treestore, &toplevel, NULL);
      gtk_tree_store_set(treestore, &toplevel,
                         COL_NAME, "Row",
                         COL_LABEL, "Row 0",
                         COL_WEIGHT_SET, TRUE,
                         COL_WEIGHT, 900,
                         COL_STOCK, GTK_STOCK_ADD,
                         COL_STOCK_VISIBLE, FALSE,
                         -1);
      /* Append a child to the second top level row, and fill in some data */
      gtk_tree_store_append(treestore, &child, &toplevel);
      gtk_tree_store_set(treestore, &child,
                         COL_NAME, "Row",
                         COL_LABEL, "Row 0:0",
                         COL_WEIGHT_SET, FALSE,
                         COL_WEIGHT, 400,
                         COL_STOCK, GTK_STOCK_DIALOG_INFO,
                         COL_STOCK_VISIBLE, TRUE,
                         -1);
      /* Append a child to the second top level row, and fill in some data */
      gtk_tree_store_append(treestore, &child, &toplevel);
      gtk_tree_store_set(treestore, &child,
                         COL_NAME, "Row",
                         COL_LABEL, "Row 0:1",
                         COL_WEIGHT_SET, FALSE,
                         COL_WEIGHT, 400,
                         COL_STOCK, GTK_STOCK_CDROM,
                         COL_STOCK_VISIBLE, TRUE,
                         -1);
     
      /* Append a child to the second top level row, and fill in some data */
      gtk_tree_store_append(treestore, &child, &toplevel);
      gtk_tree_store_set(treestore, &child,
                         COL_NAME, "Row",
                         COL_LABEL, "Row 0:2",
                         COL_WEIGHT_SET, FALSE,
                         COL_WEIGHT, 400,
                         COL_STOCK, GTK_STOCK_CDROM,
                         COL_STOCK_VISIBLE, TRUE,
                         -1);
     
      /* Append a child to the second top level row, and fill in some data */
      gtk_tree_store_append(treestore, &child, &toplevel);
      gtk_tree_store_set(treestore, &child,
                         COL_NAME, "Row",
                         COL_LABEL, "Row 0:3",
                         COL_WEIGHT_SET, FALSE,
                         COL_WEIGHT, 400,
                         COL_STOCK, GTK_STOCK_CDROM,
                         COL_STOCK_VISIBLE, TRUE,
                         -1);
     
     
      /* Append a second top level row, and fill it with some data */
      gtk_tree_store_append(treestore, &toplevel, NULL);
      gtk_tree_store_set(treestore, &toplevel,
                         COL_NAME, "Row",
                         COL_LABEL, "Row 1",
                         COL_WEIGHT_SET, TRUE,
                         COL_WEIGHT, 900,
                         COL_STOCK, GTK_STOCK_APPLY,
                         COL_STOCK_VISIBLE, FALSE,
                         -1);
     
      /* Append a child to the second top level row, and fill in some data */
      gtk_tree_store_append(treestore, &child, &toplevel);
      gtk_tree_store_set(treestore, &child,
                         COL_NAME, "Row",
                         COL_LABEL, "Row 1:0",
                         COL_WEIGHT_SET, FALSE,
                         COL_WEIGHT, 400,
                         COL_STOCK, GTK_STOCK_CONNECT,
                         COL_STOCK_VISIBLE, TRUE,
                         -1);
     
      /* Append a child to the second top level row, and fill in some data */
      gtk_tree_store_append(treestore, &child, &toplevel);
      gtk_tree_store_set(treestore, &child,
                         COL_NAME, "Row",
                         COL_LABEL, "Row 1:1",
                         COL_WEIGHT_SET, FALSE,
                         COL_WEIGHT, 400,
                         COL_STOCK, GTK_STOCK_CONNECT,
                         COL_STOCK_VISIBLE, TRUE,
                         -1);
     
      /* Append a child to the second top level row, and fill in some data */
      gtk_tree_store_append(treestore, &child, &toplevel);
      gtk_tree_store_set(treestore, &child,
                         COL_NAME, "Row",
                         COL_LABEL, "Row 1:2",
                         COL_WEIGHT_SET, FALSE,
                         COL_WEIGHT, 400,
                         COL_STOCK, GTK_STOCK_CONNECT,
                         COL_STOCK_VISIBLE, TRUE,
                         -1);
     
      /* Append a child to the second top level row, and fill in some data */
      gtk_tree_store_append(treestore, &child, &toplevel);
      gtk_tree_store_set(treestore, &child,
                         COL_NAME, "Row",
                         COL_LABEL, "Row 1:3",
                         COL_WEIGHT_SET, FALSE,
                         COL_WEIGHT, 400,
                         COL_STOCK, GTK_STOCK_CONNECT,
                         COL_STOCK_VISIBLE, TRUE,
                         -1);
     
      return GTK_TREE_MODEL(treestore);
    }
     
    static GtkWidget *
    create_view_and_model (void)
    {
      GtkWidget           *scroll;
      GtkCellRenderer     *renderer;
      GtkTreeModel        *model;
      GtkWidget           *view;
     
      view = gtk_tree_view_new ();
     
     
      /* --- Column # --- */
      GtkTreeViewColumn *col = gtk_tree_view_column_new();
      gtk_tree_view_column_set_title(col, "Shortcuts");
      gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
     
     
      //g_object_set(renderer, "weight", 800, "weight-set", TRUE, NULL);
      renderer = gtk_cell_renderer_pixbuf_new();
      gtk_tree_view_column_pack_start(col, renderer, FALSE);
      //g_object_set(renderer, "stock-id", GTK_STOCK_ABOUT, NULL);
      gtk_tree_view_column_add_attribute(GTK_TREE_VIEW_COLUMN(col), renderer, "stock-id", COL_STOCK);
      gtk_tree_view_column_add_attribute(GTK_TREE_VIEW_COLUMN(col), renderer, "visible", COL_STOCK_VISIBLE);
     
     
    //  renderer = gtk_cell_renderer_text_new();
    //  /* pack cell renderer into tree view column */
    //  gtk_tree_view_column_pack_start(col, renderer, TRUE);
    //  /* set 'text' property of the cell renderer */
    //  //g_object_set(renderer, "weight", 900, NULL);
    //  //g_object_set(renderer, "weight-set", TRUE, NULL);
    //  gtk_tree_view_column_add_attribute(GTK_TREE_VIEW_COLUMN(col), renderer, "text", COL_NAME);
    //  gtk_tree_view_column_add_attribute(GTK_TREE_VIEW_COLUMN(col), renderer, "visible", COL_STOCK_VISIBLE);
     
      renderer = gtk_cell_renderer_text_new();
      /* pack cell renderer into tree view column */
      gtk_tree_view_column_pack_start(col, renderer, FALSE);
      //g_object_set(renderer, "text", "Bazzzz!", NULL);
      //g_object_set(renderer, "weight", 900, NULL);
      gtk_tree_view_column_add_attribute(GTK_TREE_VIEW_COLUMN(col), renderer, "weight", COL_WEIGHT);
      gtk_tree_view_column_add_attribute(GTK_TREE_VIEW_COLUMN(col), renderer, "weight-set", COL_WEIGHT_SET);
      gtk_tree_view_column_add_attribute(GTK_TREE_VIEW_COLUMN(col), renderer, "text", COL_LABEL);
     
     
     
      /* --- Column #1 --- */
    //  renderer = gtk_cell_renderer_text_new ();
    //  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
    //                                               -1,
    //                                               "Name",
    //                                               renderer,
    //                                               "text", COL_NAME,
    //                                               NULL);
     
      /* --- Column #2 --- */
     
    //  renderer = gtk_cell_renderer_text_new ();
    //  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
    //                                               -1,
    //                                               "Age",
    //                                               renderer,
    //                                               "text", COL_AGE,
    //                                               NULL);
     
      model = create_and_fill_model ();
     
      gtk_tree_view_set_model (GTK_TREE_VIEW (view), model);
     
      /* The tree view has acquired its own reference to the
       *  model, so we can drop ours. That way the model will
       *  be freed automatically when the tree view is destroyed */
     
    ///  GtkTreeIter iter;
    ///  GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
    ///  GtkTreePath *path = gtk_tree_path_new_from_string("0:0");
     
      //g_object_unref (model);
      app.tree_model = model;
      app.tree_view  = view;
     
      gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
      ///gtk_tree_view_set_show_expanders(GTK_TREE_VIEW(view), FALSE);
      ///gtk_tree_view_expand_all(GTK_TREE_VIEW(view));
      gtk_tree_view_set_level_indentation (GTK_TREE_VIEW(view), 12);
      //gtk_tree_view_set_grid_lines(GTK_TREE_VIEW(view), TRUE);
     
      scroll = gtk_scrolled_window_new(NULL, NULL);
      gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
      gtk_container_add (GTK_CONTAINER (scroll), view);
     
      return scroll;
    }
    #else
     
     
     
    #endif
     
    void btn_clicked( GtkWidget *widget, gpointer data)
    {
        GtkTreeIter iter;
        GtkTreePath *path = gtk_tree_path_new_from_string(data);
        //gtk_tree_model_get_iter_from_string(app.tree_model, &iter, data);
        gtk_tree_model_get_iter(app.tree_model, &iter, path);
     
        gtk_tree_view_collapse_all(app.tree_view);
        gtk_tree_view_expand_to_path(app.tree_view, path);
     
        gtk_tree_view_set_cursor(GTK_TREE_VIEW(app.tree_view), path, 0, 0);
        gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(app.tree_view), path, NULL, TRUE, 0.5, 0.5);
     
     
        gchar *str_data = NULL;
        gtk_tree_model_get (app.tree_model, &iter,
                            COL_LABEL, &str_data,
                            -1);
        g_print("btn_clicked: %s, path = %p, %s\n", data, path, str_data);
     
        // TODO free path...
    }
     
    static GtkWidget*
    create_buttons() {
        GtkWidget *scroll;
        GtkWidget *box;
        GtkWidget *btn;
        box = gtk_vbox_new(FALSE, 0);
        scroll = gtk_scrolled_window_new(NULL, NULL);
     
        btn = gtk_button_new_with_label("Row 0");
        g_signal_connect (btn, "clicked", G_CALLBACK (btn_clicked), g_strdup("0"));
        gtk_box_pack_start(GTK_BOX(box), btn, FALSE, TRUE, 0);
     
        btn = gtk_button_new_with_label("Row 0:0");
        g_signal_connect (btn, "clicked", G_CALLBACK (btn_clicked), g_strdup("0:0"));
        gtk_box_pack_start(GTK_BOX(box), btn, FALSE, TRUE, 0);
     
        btn = gtk_button_new_with_label("Row 0:1");
        g_signal_connect (btn, "clicked", G_CALLBACK (btn_clicked), g_strdup("0:1"));
        gtk_box_pack_start(GTK_BOX(box), btn, FALSE, TRUE, 0);
     
        btn = gtk_button_new_with_label("Row 0:2");
        g_signal_connect (btn, "clicked", G_CALLBACK (btn_clicked), g_strdup("0:2"));
        gtk_box_pack_start(GTK_BOX(box), btn, FALSE, TRUE, 0);
     
        btn = gtk_button_new_with_label("Row 0:3");
        g_signal_connect (btn, "clicked", G_CALLBACK (btn_clicked), g_strdup("0:3"));
        gtk_box_pack_start(GTK_BOX(box), btn, FALSE, TRUE, 0);
     
        btn = gtk_button_new_with_label("Row 1");
        g_signal_connect (btn, "clicked", G_CALLBACK (btn_clicked), g_strdup("1"));
        gtk_box_pack_start(GTK_BOX(box), btn, FALSE, TRUE, 0);
     
        btn = gtk_button_new_with_label("Row 1:0");
        g_signal_connect (btn, "clicked", G_CALLBACK (btn_clicked), g_strdup("1:0"));
        gtk_box_pack_start(GTK_BOX(box), btn, FALSE, TRUE, 0);
     
        btn = gtk_button_new_with_label("Row 1:1");
        g_signal_connect (btn, "clicked", G_CALLBACK (btn_clicked), g_strdup("1:1"));
        gtk_box_pack_start(GTK_BOX(box), btn, FALSE, TRUE, 0);
     
        btn = gtk_button_new_with_label("Row 1:2");
        g_signal_connect (btn, "clicked", G_CALLBACK (btn_clicked), g_strdup("1:2"));
        gtk_box_pack_start(GTK_BOX(box), btn, FALSE, TRUE, 0);
     
        btn = gtk_button_new_with_label("Row 1:3");
        g_signal_connect (btn, "clicked", G_CALLBACK (btn_clicked), g_strdup("1:3"));
        gtk_box_pack_start(GTK_BOX(box), btn, FALSE, TRUE, 0);
     
        gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), box);
     
        return scroll;
    }
     
    static GtkWidget*
    create_window (void)
    {
        GtkWidget *window;
        GtkWidget *sidebar;
        GtkWidget *label;
        GtkWidget *box;
     
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
        gtk_window_set_default_size(GTK_WINDOW(window), 400, 100);
     
        box = gtk_hbox_new(FALSE, 0);
     
        sidebar = create_view_and_model();
        label = create_buttons();
     
        gtk_box_pack_start(GTK_BOX(box), sidebar, FALSE, TRUE, 0);
        gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
     
        gtk_container_add(GTK_CONTAINER(window), box);
     
        g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
     
        return window;
    }
     
    int
    main (int argc, char *argv[])
    {
        GtkWidget *window;
     
     
     
        gtk_init (&argc, &argv);
     
        window = create_window ();
        gtk_widget_show_all (window);
     
        gtk_main ();
     
     
     
        return 0;
    }


    -Mon souhait est de mettre cette ligne au milieu de la fenêtre.
    Avez vous une solution ?
    -La fonction gtk_tree_view_scroll_to_cell
    -Quand je debug[...]
    Mais, après avoir quitté la fonction Select (il faut dire que la pile des appels est très complexe), le système, prend la liberté de placer toujours dans le haut de la fenêtre l'ancien élément qui était déjà là.

    Merci,

    PS: Merci de respecter les règles du forum

  12. #12
    Nouveau membre du Club
    Inscrit en
    Décembre 2006
    Messages
    31
    Détails du profil
    Informations forums :
    Inscription : Décembre 2006
    Messages : 31
    Points : 30
    Points
    30
    Par défaut
    Bonjour à vous,

    J'ai résolu mon problème.

    Pour les intéressés :

    Code initial :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    void CTreeModel::Select(GtkTreeIter* treeIter)
    {
    	GtkTreePath*	treePath			= ::gtk_tree_model_get_path(GTK_TREE_MODEL(GetStore()), treeIter);
    	GtkTreeView*	treeView			= GTK_TREE_VIEW(GetView());
     
    	::gtk_tree_view_collapse_all(treeView);
    	::gtk_tree_view_expand_to_path(treeView, treePath);
    	::gtk_tree_view_set_cursor(treeView, treePath, 0, 0);
     
    	::gtk_tree_path_free(treePath);
    }
    Code final :
    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
     
    void CTreeModel::Select(GtkTreeIter* treeIter)
    {
    	GtkTreePath*	treePath			= ::gtk_tree_model_get_path(GTK_TREE_MODEL(GetStore()), treeIter);
    	GtkTreeView*	treeView			= GTK_TREE_VIEW(GetView());
     
    	::gtk_tree_view_collapse_all(treeView);
    	::gtk_tree_view_expand_to_path(treeView, treePath);
    	::gtk_tree_view_set_cursor(treeView, treePath, 0, 0);
     
            // obtenir le widget de type GtkScrolledWindow
    	GtkScrolledWindow*	scrolledWindow	= (GtkScrolledWindow*)(TopWidget());
     
            // obtenir son ascenseur vertical de type GtkScrolledWindow
    	GtkAdjustment*		vertAdjustment	= ::gtk_scrolled_window_get_vadjustment(scrolledWindow);
     
           // obtenir le rectangle englobant de la cellule sélectionnée
    	GdkRectangle rect;
    	::gtk_tree_view_get_cell_area(treeView, treePath, 0, &rect);
     
           // repositionner l'ascenseur
    	::gtk_adjustment_set_value (vertAdjustment, rect.y);
     
    	::gtk_tree_path_free(treePath);
    }
    Tout est dans le code et les commentaires.

    Bonne journée à vous,
    Gelu

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

Discussions similaires

  1. Réponses: 0
    Dernier message: 19/05/2008, 14h02
  2. TreeView : enfant ou parent selectionné ?
    Par LoicH dans le forum C++Builder
    Réponses: 7
    Dernier message: 31/08/2005, 23h13
  3. [ComboBox] Recuperer la ligne selectionnée
    Par webbulls dans le forum Composants
    Réponses: 4
    Dernier message: 11/07/2005, 10h49
  4. TreeView - couleur par ligne
    Par LoicH dans le forum C++Builder
    Réponses: 4
    Dernier message: 20/06/2005, 23h25

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