如何删除QTabWidget标签内的填充?

问题描述

从图像中可以看到,QTabWidget内的文本编辑器周围有一个边框。

我这样设置样式表:

tab.setStyleSheet("QTabWidget::pane { margin: 0px 0px 0px 0px; padding: 0px; border: 1px solid black; } QTabBar::tab { margin: 0px 0px 0px 0px; padding: 0px; border: 1px solid black; } QTabBar::tab:selected { background-color: #349117; }")

如果我将margin设置为负,这会有所帮助,但是事情看起来有点不合时宜,而且我也不想硬编码可能仅在我的系统上起作用而对其他系统不起作用的值。

代码如下:

import os,sys
from pyside2 import QtGui,QtCore,QtWidgets,QtWebEngineWidgets,QtWebChannel


# monaco editor index html file
file = "./index.html"

tab = QtWidgets.QTabWidget()
bgcolor = tab.palette().color(QtGui.QPalette.Background)

editor = QtWebEngineWidgets.QWebEngineView()
editor.load(QtCore.QUrl.fromLocalFile(file))
tab.setStyleSheet("QTabWidget::pane { margin: 0px 0px 0px 0px; padding: 0px; border: 1px solid black; } QTabBar::tab { margin: 0px 0px 0px 0px; padding: 0px; border: 1px solid black; } QTabBar::tab:selected { background-color: #349117; }")

tab.addTab(editor,"python1")
tab.show()

边框似乎来自显示的HTML页面。 这是HTML代码

<!DOCTYPE html>
<html>
<head>
    <Meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <Meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
</head>
<body>

<div id="container" style="min-height: calc(100vh - 40px); margin: 0; padding: 0; Box-sizing: border-Box; border: 0px"></div>

<script src="monaco-editor/min/vs/loader.js"></script>
<script>
    require.config({ paths: { 'vs': 'monaco-editor/min/vs' }});
    require(['vs/editor/editor.main'],function() {
        var editor = monaco.editor.create(document.getElementById('container'),{
            value: [
                'function x() {','\tconsole.log("Hello World!");','}'
            ].join('\n'),language: 'python',fontFamily:"Verdana",fontSize: "20px",lineNumbers: "on",roundedSelection: false,scrollBeyondLastLine: true,readOnly: false,formatOnPaste: true,insertSpaces: true,automaticLayout: true,theme: "vs-dark"
        });
    });
</script>
</body>
</html>

enter image description here

解决方法

该填充是用HTML生成的,可以使用CSS删除:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
</head>
<style >
    #container {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

</style>
<body>

<div id="container"></div>
<script src="monaco-editor/min/vs/loader.js"></script>
<script>
    require.config({ paths: { 'vs': 'monaco-editor/min/vs' }});
    require(['vs/editor/editor.main'],function() {
        var editor = monaco.editor.create(document.getElementById('container'),{
            value: [
                'function x() {','\tconsole.log("Hello world!");','}'
            ].join('\n'),language: 'python',fontFamily:"Verdana",fontSize: "20px",lineNumbers: "on",roundedSelection: false,scrollBeyondLastLine: true,readOnly: false,formatOnPaste: true,insertSpaces: true,automaticLayout: true,theme: "vs-dark"
        });
    });
</script>
</body>
</html>

enter image description here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...