使笔记本选项卡锚定,使其位置无法更改

发布于 2025-01-07 19:46:37 字数 458 浏览 4 评论 0原文

我有一个 GtkNotebook,它至少包含一个永久选项卡,称为“搜索”。此页面中的小部件允许创建更多页面,并且这些页面有一个包含关闭按钮的选项卡。

如何使选项卡可重新排序,同时将“搜索”选项卡固定在位置 0? gtk.Notebook.set_tab_reorderable() 的当前行为是,它允许您物理拖动选项卡以对其进行重新排序...当可重新排序的选项卡移过它时,它不会阻止该选项卡被迫重新排序。

示例:

第一个图像是默认位置:

在此处输入图像描述

该图像是拖动 Row#6( 其中第 6 行可重新排序,但搜索不可重新排序): 在此处输入图像描述

如何防止“搜索”被“可重新排序”选项卡重新排序?

I have a GtkNotebook that will contain at the very least, one permanent tab, called "Search". The widget within this page allows for more pages to be created, and these pages have a tab that contains a close button.

How do I make the tabs reorderable, but also keep the "Search" tab anchored at position 0? The current behavior of gtk.Notebook.set_tab_reorderable() is that it allows you to physically drag a tab to reorder it...it doesn't stop that tab from being forced to reorder itself when a reorderable tab moves past it.

Example:

This first image is the default positions:

enter image description here

This image is the result of dragging Row#6( where Row#6 is reorderable but Search isn't):
enter image description here

How do I keep "Search" from being reordered by 'reorderable' tabs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不醒的梦 2025-01-14 19:46:37

在我看来,一个可能的解决方案是连接到 'page-reordered' 信号,如下所示:

import gtk

 def on_reorder(notebook, child, number, user_data):
     if number == 0:
         notebook.reorder_child(user_data, 0)

 def main():
     mainwin = gtk.Window()
     notebook = gtk.Notebook()
     mainwin.add(notebook)
     mainwin.set_default_size(200,200)
     for label in ['Search', 'Row#6', 'Row#9']:
         child = gtk.VBox()
         notebook.append_page(child, gtk.Label(label))
         if label != 'Search':
             notebook.set_tab_reorderable(child, True)
         else:
             notebook.set_tab_reorderable(child, False)
     searchtab = notebook.get_nth_page(0)
     notebook.connect('page-reordered', on_reorder, searchtab)

     mainwin.show_all()
     mainwin.connect('destroy', gtk.main_quit)
     gtk.main()

 if __name__ == "__main__":
     main()   

希望它有帮助。

Seems to me like a possible solution would be to connect to the 'page-reordered' signal like this:

import gtk

 def on_reorder(notebook, child, number, user_data):
     if number == 0:
         notebook.reorder_child(user_data, 0)

 def main():
     mainwin = gtk.Window()
     notebook = gtk.Notebook()
     mainwin.add(notebook)
     mainwin.set_default_size(200,200)
     for label in ['Search', 'Row#6', 'Row#9']:
         child = gtk.VBox()
         notebook.append_page(child, gtk.Label(label))
         if label != 'Search':
             notebook.set_tab_reorderable(child, True)
         else:
             notebook.set_tab_reorderable(child, False)
     searchtab = notebook.get_nth_page(0)
     notebook.connect('page-reordered', on_reorder, searchtab)

     mainwin.show_all()
     mainwin.connect('destroy', gtk.main_quit)
     gtk.main()

 if __name__ == "__main__":
     main()   

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文