Python PyQt窗口小部件边缘切断

Python PyQt窗口小部件边缘切断,python,terminal,pyqt,Python,Terminal,Pyqt,我正在制作一个小脚本,它将xterm嵌入到一个小GUI中。当我运行我的尝试时,终端部件的边缘被切断,我不知道为什么。如何显示完整的终端 #!/usr/bin/env python import sys from PyQt4 import QtCore, QtGui class embedded_terminal(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self

我正在制作一个小脚本,它将xterm嵌入到一个小GUI中。当我运行我的尝试时,终端部件的边缘被切断,我不知道为什么。如何显示完整的终端

#!/usr/bin/env python

import sys
from PyQt4 import QtCore, QtGui

class embedded_terminal(QtGui.QWidget):

    def __init__(self):

        QtGui.QWidget.__init__(self)
        self._processes = []
        self.resize(1200, 800)

        # layout

        self.layout = QtGui.QVBoxLayout(self)

        # buttons

        button_list = self.command_button(
            title   = "ls",
            command = "ls"
        )
        button_terminate = QtGui.QPushButton("terminate")
        button_terminate.clicked.connect(lambda: self.terminate())
        # style buttons and add buttons to layout
        buttons = []
        buttons.append(button_list)
        buttons.append(button_terminate)
        for button in buttons:
            self.set_button_style(button)
            self.layout.addWidget(button)

        # terminal

        self.terminal = QtGui.QWidget(self)
        self.layout.addWidget(self.terminal)
        self.start_process(
            "xterm",
                [
                    "-fn",
                    "-misc-fixed-*-*-*-*-18-*-*-*-*-*-*-*",
                    "-into",
                    str(self.terminal.winId()),
                    "-e",
                    "tmux",
                    "new",
                    "-s",
                    "session1"
                ]
        )

    def start_process(
        self,
        program,
        options
        ):
        child = QtCore.QProcess()
        self._processes.append(child)
        child.start(program, options)

    def run_command(
        self,
        command = "ls"
        ):
        program = "tmux"
        options = []
        options.extend(["send-keys", "-t", "session1:0"])
        options.extend([command])
        options.extend(["Enter"])
        self.start_process(program, options)

    def command_button(
        self,
        title   = None,
        command = None
        ):
        button = QtGui.QPushButton(title)
        button.clicked.connect(lambda: self.run_command(command = command))
        return button

    def set_button_style(
        self,
        button
        ):
        # Set button style.
        button.setStyleSheet(
            """
            color: #{color1};
            background-color: #{color2};
            border: 1px solid #{color1};
            """.format(
                color1 = "3861aa",
                color2 = "ffffff"
            )
        )
        # Set button dimensions.
        button.setFixedSize(
            300,
            60
        )

    def terminate(self):
        program = "tmux"
        options = []
        options.extend(["send-keys", "-t", "session1:0"])
        options.extend(["killall tmux"])
        options.extend(["Enter"])
        self.start_process(program, options)
        QtGui.QApplication.instance().quit()

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    main = embedded_terminal()
    main.show()
    sys.exit(app.exec_())


您的
QWidget
有一个关联的
QVerticalLayout
,因此根据文档,默认情况下它只垂直延伸,因此您应该手动设置大小策略。试着这样做:

self.terminal.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

您的
QWidget
有一个关联的
QVerticalLayout
,因此根据文档,默认情况下它只垂直延伸,因此您应该手动设置大小策略。试着这样做:

self.terminal.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

您的
QWidget
有一个关联的
QVerticalLayout
,因此根据文档,默认情况下它只垂直延伸,因此您应该手动设置大小策略。试着这样做:

self.terminal.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

您的
QWidget
有一个关联的
QVerticalLayout
,因此根据文档,默认情况下它只垂直延伸,因此您应该手动设置大小策略。试着这样做:

self.terminal.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

这是因为
terminal
小部件比
xterm
窗口大。你可以替换

self.terminal = QtGui.QWidget()

并查看
终端的实际大小。我找到的解决方案是将
terminal
初始大小设置为接近
xterm
窗口大小:

self.terminal.setFixedSize(730, 440)

这是因为
terminal
小部件比
xterm
窗口大。你可以替换

self.terminal = QtGui.QWidget()

并查看
终端的实际大小。我找到的解决方案是将
terminal
初始大小设置为接近
xterm
窗口大小:

self.terminal.setFixedSize(730, 440)

这是因为
terminal
小部件比
xterm
窗口大。你可以替换

self.terminal = QtGui.QWidget()

并查看
终端的实际大小。我找到的解决方案是将
terminal
初始大小设置为接近
xterm
窗口大小:

self.terminal.setFixedSize(730, 440)

这是因为
terminal
小部件比
xterm
窗口大。你可以替换

self.terminal = QtGui.QWidget()

并查看
终端的实际大小。我找到的解决方案是将
terminal
初始大小设置为接近
xterm
窗口大小:

self.terminal.setFixedSize(730, 440)

嗨,亚历山大·卢森科。谢谢你的解决方案,它工作得很好,谢谢你解释我如何思考终端的大小。嗨,亚历山大·卢森科。谢谢你的解决方案,它工作得很好,谢谢你解释我如何思考终端的大小。嗨,亚历山大·卢森科。谢谢你的解决方案,它工作得很好,谢谢你解释我如何思考终端的大小。嗨,亚历山大·卢森科。感谢您的解决方案,它工作得很好,感谢您解释我如何考虑终端的大小。