Skip to content
Snippets Groups Projects
Commit 2d33ab50 authored by Thomas Holene Løkkeborg's avatar Thomas Holene Løkkeborg
Browse files

#18 scene & view for én side

parent e600101e
No related branches found
No related tags found
1 merge request!3#18 MVP brukergrensesnitt - inline edit view
Pipeline #71069 passed
"""Hovedvinduet."""
import sys
import os
from PySide2.QtCore import QRectF, QPoint, QTimer
from PySide2.QtCore import QRectF, QPoint, QTimer, Qt
from PySide2.QtWidgets import QTabWidget, QWidget, QMainWindow, QApplication, \
QHBoxLayout, QVBoxLayout, QPushButton, QTreeWidget, QGraphicsScene, \
QGraphicsView, QAction
from PySide2 import QtGui
QGraphicsView, QAction, QScrollArea, QGraphicsRectItem
from PySide2.QtGui import QBrush, QIcon, QPalette
class MainWindow(QMainWindow):
......@@ -92,7 +92,7 @@ class MainWindow(QMainWindow):
filename = 'media/HVlogo.PNG'
dirname = os.path.dirname(__file__)
filepath = os.path.join(dirname, filename)
self.setWindowIcon(QtGui.QIcon(filepath))
self.setWindowIcon(QIcon(filepath))
class MainWidget(QWidget):
......@@ -135,10 +135,43 @@ class ViewArea(QWidget):
def __init__(self):
super().__init__()
self.layout = QHBoxLayout()
self.layout = QHBoxLayout(self)
self.scroll_area = QScrollArea(self)
# necessary to make the scroll area fill the space it's given
self.scroll_area.setWidgetResizable(True)
# scene and view widgets
self.scene = QGraphicsScene()
self.setup_scene()
self.view = QGraphicsView(self.scene)
self.view.scale(0.50, 0.50)
self.scroll_area.setWidget(self.view)
self.layout.addWidget(self.scroll_area)
self.setLayout(self.layout)
self.launch_auto_zoom()
def setup_scene(self):
"""Prepare scene for use.
Draws borders, background, etc.
"""
self.scene.setSceneRect(QRectF(0, 0, self.WIDTH, self.HEIGHT))
# sets the background color of the scene to be the appropriate
# system-specific background color
# source: https://stackoverflow.com/a/23880531/3545896
# source: https://stackoverflow.com/questions/15519749/how-to-get-widget-background-qcolor
self.scene.setBackgroundBrush(app.palette().color(QPalette.Window))
# color the page white
page_background = QGraphicsRectItem(0, 0, self.WIDTH, self.HEIGHT)
page_background.setBrush(QBrush(Qt.white))
self.scene.addItem(page_background)
# draw borders
self.scene.addRect(0, 0, self.WIDTH, self.HEIGHT)
self.scene.addRect(self.PADDING, self.PADDING, self.CONTENT_WIDTH,
self.CONTENT_HEIGHT)
......@@ -147,14 +180,6 @@ class ViewArea(QWidget):
self.scene.addRect(self.PADDING, self.PADDING, self.CONTENT_WIDTH,
self.HEADER_HEIGHT)
self.view = QGraphicsView(self.scene)
self.view.scale(0.50, 0.50)
self.layout.addWidget(self.view)
self.setLayout(self.layout)
self.launch_auto_zoom()
def launch_auto_zoom(self):
"""Zoom in a regular interval.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment