CSS边距未应用于Gtk文本视图 [英] CSS margins not being applied to a Gtk textview

查看:58
本文介绍了CSS边距未应用于Gtk文本视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下最小的可重现示例代码:

I have the following minimal reproducible example code:

#!/usr/bin/python3
#-*-coding: utf-8-*-

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk

win = Gtk.Window()
win.connect("destroy", lambda _: Gtk.main_quit())
box = Gtk.VBox()
win.add(box)
view = Gtk.TextView()
buf = view.get_buffer()
buf.set_text("Hello, this is some text !")
prov = Gtk.CssProvider.new()
prov.load_from_data("""
text {
    color: red;
    background-color: yellow;
    margin: 30px;
}
""".encode())
ctx = win.get_style_context()
ctx.add_provider_for_screen(Gdk.Screen.get_default(), prov, 800)
box.add(view)
win.show_all()
Gtk.main()

字体和背景变色,但未应用边距.为什么,它将如何解决?

The font and background gets colored, but the margins are not applied. Why, and what would fix it ?

注意:当我使用以下CSS将边距应用于框时

Note : When I apply the margins to the box with following CSS

text {
    color: red;
    background-color: yellow;
}
box {
    margin: 30px;
}

或添加`pythonview.set("margin-left",10)view.set(" margin_right,10)...

or add `python view.set("margin-left", 10) view.set("margin_right, 10) ...

the margins are applied. So the cause must be a wrong selector ...

推荐答案

textview中没有空白的CSS节点.您需要使用 set_left_margin(left_margin) set_right_margin(right_margin) set_justification(justification)之类的函数.

There are not css nodes to margins in textview. You need to use functions like set_left_margin(left_margin) set_right_margin(right_margin) or set_justification(justification).

用法

Gtk.TextView().set_left_margin(10) /*value is in pixels*/

CSS节点

textview.view
├── border.top
├── border.left
├── text
│   ╰── [selection]
├── border.right
├── border.bottom
╰── [window.popup]

css节点仅出现在c文档 c文档

css nodes only appears in c docs c documentation

这是py文档 py文档

这篇关于CSS边距未应用于Gtk文本视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆