「コメント」にコードを入力できないため、回答として回答しています。
DrawingArea
に対応するEventMask
を有効にする必要があると思われます。これは他のウィジェットとは多少異なっていると思います。
以下
がPython3
に小さなデモプログラムである(これは基本的にGtk3.2xライブラリに直接接続するので、あなたはarea_button_press()
意志でFalse
に復帰True
を変更C.
で何をしたいかのようになります。 。予想通りbutton_press_event
にそれを透明にする、...add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
の行をコメントすることは全く認識されるようにbutton-press-event
を作るために、コードで必要とされる:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# test_headerbar_events.py
#
# Copyright 2017 John Coppens <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
from gi.repository import Gtk, Gdk
class MainWindow(Gtk.Window):
def __init__(self):
super(MainWindow, self).__init__()
self.connect("destroy", lambda x: Gtk.main_quit())
self.set_default_size(200, -1)
hdrbar = Gtk.HeaderBar(title = "Header bar")
hdrbar.connect("button-press-event", self.hdrbar_button_press)
drawing_area = Gtk.DrawingArea()
drawing_area.set_size_request(30, 30)
drawing_area.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
drawing_area.connect("button-press-event", self.area_button_press)
frame = Gtk.Frame()
frame.add(drawing_area)
hdrbar.pack_start(frame)
self.add(hdrbar)
self.show_all()
def area_button_press(self, btn, event):
print("Button pressed on Drawing Area")
return True
def hdrbar_button_press(self, btn, event):
print("Button pressed on Header Bar")
return False
def run(self):
Gtk.main()
def main(args):
mainwdw = MainWindow()
mainwdw.run()
return 0
if __name__ == '__main__':
import sys
sys.exit(main(sys.argv))
EDIT:set_titlebar()
を使用すると、イベントはウィンドウマネージャで直接表示されるように見えます。あなたは、ウィンドウの動きを(ブロック)を制御したい場合は、
set_titlebar()
を使用すると、ウィンドウのタイトルバーを隠し、一番上にheaderbarが表示されますされ、set_decorations(False)
使用できませんでした。その後、イベントは制御可能になります。ヘッダーバーとウィンドウの残りの内容を格納するには、VBoxを使用します。
もちろんです。この方法では、自分でドラッグするウィンドウを実装する必要があります(あまり複雑ではありません)。必要に応じて、(年前に - あなたはGtkの呼び出しを微調整する必要があるかもしれません)GUI frontend I made for the Wcalc calculatorを見て、
は、イベントをキャプチャしている、あなたの描画要素にインストールされているすべてのハンドラ(複数可)がありますか?基本的なウィジェットにイベントを許可するには、これらのハンドラを偽で終了する必要があることを覚えておいてください。カスタムウィジェットをどのように描画しますか? – jcoppens
@jcoppensには、モーション通知イベント、ボタンプレスイベント、ボタンリリースイベントの3つのハンドラーがあります。私はそれらを潜在的なウィジェット(GtkHeaderBar、正確には)に伝播させないようにしたいので、私はTRUEを返します。以前は動作していましたが、新しいGTKバージョンでは動作しなくなりました。私はCairoを使って "draw"コールバックに描画します。 – NK22