GTK4 - Change Window Size When A Dialog (Modal) Is Shown
Steps to reproduce
- Run the example code.
- This code generates a main window, a preferences window (modal) and a message dialog (modal).
- Open preferences window and click the button to change size of the main window.
- See the result.
Current behavior
The main window is resized for a very small time (less than a second) and the previous size is set again. In other words, the main window is not resized when preferences window and message dialog is open.
Expected outcome
The code changes size the main window.
Version information
- GTK 4.8.2
- Debian 11.5 based distribution (Flatpak application). Also RPM based distribution (default GTK4).
- I did not built the GTK.
Additional information
Window is resized if the message dialog is not set as modal when it is generated. But after generating the message dialog, setting the modal value as False, running the code for resizing the main window and setting the modal value as True does not work (the window is not resized). See the comment lines in the example code.
Example code:
import gi
gi.require_version('Gtk', '4.0')
gi.require_version('Gdk', '4.0')
from gi.repository import Gtk, Gdk
def on_activate(app):
global win, win2, messagedialog
win = Gtk.ApplicationWindow(application=app)
win.set_default_size(500, 500)
tv = Gtk.TreeView()
win.set_child(tv)
btn = Gtk.Button()
win.set_child(btn)
btn.set_label("button")
btn.set_halign(Gtk.Align.CENTER)
btn.set_valign(Gtk.Align.CENTER)
btn.connect("clicked", on_btn_clicked)
win2 = Gtk.Window()
win2.set_title("Preferences")
win2.set_default_size(200, 200)
win2.set_resizable(False)
win2.set_transient_for(win)
win2.set_modal(True)
win2.set_hide_on_close(True)
btn2 = Gtk.Button()
win2.set_child(btn2)
btn2.set_label("Default Window Size")
btn2.set_halign(Gtk.Align.CENTER)
btn2.set_valign(Gtk.Align.CENTER)
btn2.connect("clicked", on_btn2_clicked)
messagedialog = Gtk.MessageDialog(transient_for=win2, modal=True, title="",
message_type=Gtk.MessageType.WARNING,
buttons=Gtk.ButtonsType.YES_NO,
text="Text", secondary_text="")
messagedialog.connect("response", response_func)
win.present()
def on_btn_clicked(widget):
win2.present()
def on_btn2_clicked(widget):
messagedialog.present()
#win.set_default_size(100, 100)
def response_func(dialog, response):
if response == Gtk.ResponseType.YES:
#dialog.set_modal(False)
win.set_default_size(100, 100)
#dialog.set_modal(True)
dialog.hide()
app = Gtk.Application()
app.connect('activate', on_activate)
app.run(None)