Fullscreened window and changing texts in labels


Hello all.
I need again help with my testing app in gtk4 in C++.

I have second display conected to my notebook.
I need second app window to be fullscreened on the second display and than I need change text in its labels.

In my app for first I create second window with pressing button “Open new win”.

Than with second button “Set win full screen” maximalize this window on second display.

Up to here is everything okay.

When I want change texts in its labels with third button “change texts” - texts are changed, but problem is that sometimes (not all times) is second column
at left side of window added (marked with red rectangle). In this new coumn are old texts.

see attached pictures (maximalized-ok.jpg and changed-nok.jpg )

Please coluld anybody give me any advice - what is wrong in my app.

Thanks a Lot!

here is my code:

#include <gtk/gtk.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

GtkWidget *newWin, *vBox;
vector<GtkWidget*> vectorWidgetu;

void CloseWin (GtkWidget* wid, GtkWidget* data) {
    cout << "CloseWin" << endl;

    //do something

  gtk_window_close (GTK_WINDOW(data));

void SetFull (GtkWidget* wid, GtkWidget* data) {
    cout << "SetFull" << endl;

    //zjistime si seznam monitoru
    GdkDisplay *display = gdk_display_get_default();
    GListModel *seznam = gdk_display_get_monitors(display);

    //zjistime si pocet detekovanych monitoru
    int displayCnt = g_list_model_get_n_items(seznam);
    cout << "pocet detekovanych monitoru: " << displayCnt << endl;

    //projdem si vsechny monitory a vypisem si jejich typ a vyrobce (ale moc toho to nerekne)
    for (int i = 0; i< displayCnt; ++i) {
        gpointer polozka = g_list_model_get_item(seznam,i);

        cout << i << ":typ monitoru:" << gdk_monitor_get_model(GDK_MONITOR(polozka)) << " " << gdk_monitor_get_manufacturer(GDK_MONITOR(polozka))  << endl;

    //okno fulscreennem na druhem monitoru
    if (displayCnt > 1) {
        cout << "maximalizujeme na 2. monitoru" << endl;
        if (GTK_IS_WINDOW(newWin)) {
            gpointer moni = g_list_model_get_item(seznam,1);
        } else {
            cout << "nedelame nic - otevrel jsi uz nove okno?" << endl;
        cout << "nemuzeme maximalizovat na 2. displeji, protoze byl detekovan pouze jeden" << endl;


void OpenNewWin (GtkWidget* wid, GtkWidget* data) {
    cout << "opening"<< endl;

    newWin = gtk_window_new ();
    gtk_widget_set_size_request (newWin, 220, 220);

    vBox = gtk_box_new (GTK_ORIENTATION_VERTICAL,10);
    gtk_window_set_child (GTK_WINDOW (newWin), vBox);

    for (int i = 0; i < 15; ++i)
        GtkWidget *label = gtk_label_new(("text" + to_string(i)).c_str());
        gtk_box_append  (GTK_BOX (vBox), label);

    GtkWidget *btnClose = gtk_button_new_with_label("Close");
    gtk_box_append  (GTK_BOX (vBox), btnClose);
    g_signal_connect(G_OBJECT(btnClose), "clicked", G_CALLBACK(CloseWin), newWin);

    gtk_widget_show (newWin);

void ChangeTexts (GtkWidget* wid, GtkWidget* data) {
    GtkWidget *lab;
    string texty[10] = {"aaaa", "bbbb", "cccc", "ddddd", "e", "ff", "ggg", "hhh", "ii", "jjjjjj"};
    int index =  ( std::rand() % ( 10 ) );
    cout << "selected index=" << index << endl;
    for (unsigned int i =0; i < vectorWidgetu.size(); ++i){
        lab = vectorWidgetu.at(i);


static void appActivate (GApplication *app, gpointer user_data) {
    GtkWidget *win = gtk_application_window_new (GTK_APPLICATION (app));
    gtk_window_set_title (GTK_WINDOW (win), "Title");
    gtk_window_set_default_size (GTK_WINDOW (win), 400, 300);

    GtkWidget  *vBox = gtk_box_new (GTK_ORIENTATION_VERTICAL,10);

    gtk_window_set_child (GTK_WINDOW (win), vBox);

    GtkWidget *btnOpen = gtk_button_new_with_label("Open new win");
    gtk_box_append  (GTK_BOX (vBox), btnOpen);
    g_signal_connect_swapped(GTK_BUTTON(btnOpen), "clicked", G_CALLBACK(OpenNewWin), win);

    GtkWidget *btnSetFull = gtk_button_new_with_label("Set win full screen");
    gtk_box_append  (GTK_BOX (vBox), btnSetFull);
    g_signal_connect_swapped(GTK_BUTTON(btnSetFull), "clicked", G_CALLBACK(SetFull), win);

    GtkWidget *btnChange = gtk_button_new_with_label("change texts");
    gtk_box_append  (GTK_BOX (vBox), btnChange);
    g_signal_connect_swapped(GTK_BUTTON(btnChange), "clicked", G_CALLBACK(ChangeTexts), win);

    gtk_widget_show (win);

int main(int argc, char **argv) {
    GtkApplication *app;
    app = gtk_application_new ("testing.app", G_APPLICATION_FLAGS_NONE);
    g_signal_connect (app, "activate", G_CALLBACK (appActivate), NULL);
    return g_application_run (G_APPLICATION (app), NULL, NULL);
    g_object_unref (app);

    return 0;

maximalized-ok.jpg :

changed-nok.jpg :

after some testing it seems that problem was solwed with upgrading gtk from 4.6 to 4.10

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.