如何使QGraphicsView在绘制超出其大小的线条时增加其大小?

时间:2017-05-28 19:17:01

标签: python qt pyqt4

我有这个屏幕:

enter image description here

在它上面,我绘制了一条走出董事会的线:

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

import sys
from PyQt4 import QtGui, QtCore

class Example(QtGui.QWidget):

    def __init__(self):
        super(Example, self).__init__()
        self.initUI()

    def initUI(self):
        self.drawingPanel = DrawingPanel(self)

        verticalLayout = QtGui.QVBoxLayout( self )
        verticalLayout.addWidget(self.drawingPanel)

        self.setLayout( verticalLayout )
        # self.setGeometry(300, 300, 400, 300)
        self.resize( 400, 300 )

        self.setWindowTitle('Review')
        self.show()


class DrawingPanel(QtGui.QGraphicsView):

    def __init__(self, parent):
        QtGui.QGraphicsView.__init__(self, parent)
        self.setScene(QtGui.QGraphicsScene(self))
        self.setSceneRect(QtCore.QRectF(self.viewport().rect()))

        # self.setSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Maximum)

        pencil = QtGui.QPen(QtCore.Qt.black, 2, QtCore.Qt.SolidLine)
        pencil.setStyle(QtCore.Qt.DotLine)

        self.scene().addLine(QtCore.QLineF(0, 0, 300, 600), pencil)


def main():

    app = QtGui.QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

如何让面板创建一个滚动条并能够显示绘制的整条线?

我可以找到一些其他问题:

  1. QGraphicsView / QGraphicsScene size matching
  2. QGraphicsView / QGraphicsScene image size

1 个答案:

答案 0 :(得分:0)

我修复了它只是从代码中删除了这一行:

<?php
    $username = $_POST['username'];
?>

<script type="text/javascript">
    // Change the username
    var phpusername = "<?php echo $username; ?>";
    if(phpusername == (undefined || null)) {
        (This is where the default condition code will go)
    } else {
        (This is where code will run when user updates username)
    }
</script>

enter image description here

self.setSceneRect(QtCore.QRectF(self.viewport().rect()))