title: PyQt5 QgraphicsView width and height
body: <p><strong>file:main.py</strong></p>
  <pre>
  # -*- coding: utf-8 -*-
  
  # Form implementation generated from reading ui file 'main.ui'
  #
  # Created by: PyQt5 UI code generator 5.15.2
  #
  # WARNING: Any manual changes made to this file will be lost when pyuic5 is
  # run again.  Do not edit this file unless you know what you are doing.
  
  
  from PyQt5 import QtCore, QtGui, QtWidgets
  
  
  class Ui_MainWindow(object):
      def setupUi(self, MainWindow):
          MainWindow.setObjectName("MainWindow")
          MainWindow.resize(800, 600)
          self.centralwidget = QtWidgets.QWidget(MainWindow)
          self.centralwidget.setObjectName("centralwidget")
          self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
          self.gridLayout.setContentsMargins(0, 0, 0, 0)
          self.gridLayout.setSpacing(0)
          self.gridLayout.setObjectName("gridLayout")
          self.scrollArea = QtWidgets.QScrollArea(self.centralwidget)
          self.scrollArea.setWidgetResizable(True)
          self.scrollArea.setObjectName("scrollArea")
          self.scrollAreaWidgetContents = QtWidgets.QWidget()
          self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 798, 598))
          self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
          self.gridLayout_2 = QtWidgets.QGridLayout(self.scrollAreaWidgetContents)
          self.gridLayout_2.setContentsMargins(0, 0, 0, 0)
          self.gridLayout_2.setSpacing(0)
          self.gridLayout_2.setObjectName("gridLayout_2")
          self.graphicsView = QtWidgets.QGraphicsView(self.scrollAreaWidgetContents)
          self.graphicsView.setMinimumSize(QtCore.QSize(0, 0))
          self.graphicsView.setObjectName("graphicsView")
          self.gridLayout_2.addWidget(self.graphicsView, 0, 0, 1, 1)
          self.scrollArea.setWidget(self.scrollAreaWidgetContents)
          self.gridLayout.addWidget(self.scrollArea, 0, 0, 1, 1)
          MainWindow.setCentralWidget(self.centralwidget)
  
          self.retranslateUi(MainWindow)
          QtCore.QMetaObject.connectSlotsByName(MainWindow)
  
      def retranslateUi(self, MainWindow):
          _translate = QtCore.QCoreApplication.translate
          MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
  
  
  if __name__ == "__main__":
      import sys
      app = QtWidgets.QApplication(sys.argv)
      MainWindow = QtWidgets.QMainWindow()
      ui = Ui_MainWindow()
      ui.setupUi(MainWindow)
      MainWindow.show()
      sys.exit(app.exec_())
  
  </pre>
  <p><strong>file: run_me.py</strong></p>
  <pre>
  from PyQt5 import QtCore, QtGui, QtWidgets
  from PyQt5.QtCore import Qt
  from main import Ui_MainWindow as Ui_MainWindow
  
  import sys
  
  class Main_Code:
      def __init__(self):
          self.app = QtWidgets.QApplication(sys.argv)
          self.MainWindow = QtWidgets.QMainWindow()
          self.ui = Ui_MainWindow()
          self.ui.setupUi(self.MainWindow)
          self.MainWindow.showMaximized()
          
          self.set_input_data()
          self.set_view_variables()
          self.print_lines()
          
          sys.exit(self.app.exec_())
      
      
      def set_input_data(self):
          self.schedule_items = []
          self.schedule_items.append({"title":"Title for schedule item 1","duration milliseconds":1000*51})
          self.schedule_items.append({"title":"Title for schedule item 2","duration milliseconds":1000*120})
          self.schedule_items.append({"title":"Title for schedule item 3","duration milliseconds":1000*500})
          self.live_duration = 1000*60*60*2.5 #2 hours and 30 minutes
      
          
      def set_view_variables(self):
          self.header_timeline_height = 40
          self.schedule_items_height_spacing = 50
          self.schedule_item_timeline_height = 40
          self.schedule_item_movable_height = 120
          
          #get QGraphicsView dimensions
          self.ui.graphicsView.setAlignment(Qt.AlignTop | Qt.AlignLeft)
          self.available_width = self.ui.graphicsView.width()
          self.available_height = self.ui.graphicsView.height() 
          self.ui.graphicsView.resize(self.available_width, self.available_height)
          
          
      def print_lines(self):
          #print timeline line (top)
          self.MainWindow.setStyleSheet("background-color: black;")
          self.ui.graphicsView.setStyleSheet("background-color: yellow;")
          self.scene = QtWidgets.QGraphicsScene()
          self.scene.setBackgroundBrush(QtGui.QBrush(Qt.red))
          self.ui.graphicsView.setScene(self.scene)
          self.ui.graphicsView.setSceneRect(0,0,self.available_width,self.available_height)
          
          self.timeline_line_top = QtWidgets.QGraphicsLineItem(0,self.MainWindow.height(),self.available_width,0)
          self.scene.addItem( self.timeline_line_top )
          
  program = Main_Code()
  </pre>
  <p>I am trying to draw a line from the bottom left corner to the top right corner.</p>
  <p>With the above code the output is:
  <a href="https://i.stack.imgur.com/cLoUc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cLoUc.png" alt="enter image description here" /></a></p>
  <p>I think this is maybe a scale problem (variables self.available_width,self.available_height).</p>
  <p>What I am doing wrong?</p>