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

#98 forbedret fritekstmodul sin egne lineedit & bruker i ny modul

parent 4da7b43f
No related branches found
No related tags found
1 merge request!73#98 Kodefrasemodul
......@@ -52,12 +52,16 @@ class TableWithSizeOfContent(QTableWidget):
QHeaderView.ResizeMode.ResizeToContents
)
# TODO this would be ideal, but it massively increases the width of the thing... should only stretch until minimal sizehint of lineedit
# TODO hvis ikke kan løse, fjern border til høyre på siste kolonne :) (celle)
#self.horizontalHeader().setStretchLastSection(True)
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
# Tells Qt that we'd like the widget to be the one given by
# self.sizeHint
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
# See class docstring
self.cellChanged.connect(
......@@ -175,8 +179,18 @@ class CodePhraseModule(QWidget):
QWidget.__init__(self)
ModuleBase.__init__(self)
self.line_edit_header = LineEditWithSizeOfContent("Kodefraser")
self.line_edit_header.setFont(HEADLINE_FONT)
self.table = TableWithSizeOfContent(0, 2)
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
# See class docstring
self.line_edit_header.textChanged.connect(lambda : (self.line_edit_header.updateGeometry(), self.adjustSize()))
self.table.cellChanged.connect(
lambda: self.adjustSize()
)
self.database = database
self.category = self.get_category()
......@@ -191,14 +205,11 @@ class CodePhraseModule(QWidget):
# than one row
self.add_row()
# See class docstring
self.table.cellChanged.connect(
lambda: (self.adjustSize())
)
self.layout = QVBoxLayout()
self.layout.setSpacing(0)
self.layout.setMargin(0)
self.layout.addWidget(self.line_edit_header)
self.layout.addWidget(self.table)
self.setLayout(self.layout)
......
......@@ -29,11 +29,7 @@ class TextEditWithSizeOfContent(QTextEdit):
def sizeHint(self):
"""Give size hint using width of text."""
size = QSize(self.document().size().toSize())
# NOTE that the following is not respected for dimensions below 100,100
size.setWidth(max(100, size.width()))
size.setHeight(max(100, size.height()))
return size
return QSize(self.document().size().toSize())
def resizeEvent(self, event):
"""Update geometry before handling the resizeEvent.
......@@ -67,18 +63,20 @@ class LineEditWithSizeOfContent(QLineEdit):
content_width += 10
return QSize(content_width, size_hint_parent.height())
def resizeEvent(self, event):
"""Update geometry before handling the resizeEvent.
def minimumSizeHint(self):
"""Overriden to set the minimal size as the size hint.
See sources in module docstring.
Override of https://doc.qt.io/qt-5/qwidget.html#minimumSize-prop
because we are unable to `self.setMinimalSize` to a size under 87,87.
Not sure why, but simply returning our sizeHint is a valid workaround,
since we would be setting self.minimalSize to this anyway.
Parameters
----------
event : QResizeEvent
event sent by Qt
Returns
-------
QSize
The minimal size for this widget
"""
self.updateGeometry()
super(LineEditWithSizeOfContent, self).resizeEvent(event)
return self.sizeHint()
class Meta(type(ModuleBase), type(QWidget)):
......@@ -119,7 +117,7 @@ class FreeTextModule(ModuleBase, QWidget, metaclass=Meta):
# widget will leave behind gray color when it is shrunk in the
# QGraphicsScene
self.line_edit_header.textChanged.connect(
lambda: (self.line_edit_header.adjustSize(), self.adjustSize())
lambda: (self.line_edit_header.updateGeometry(), self.adjustSize())
)
self.text_edit_body.textChanged.connect(
lambda: (self.text_edit_body.adjustSize(), self.adjustSize())
......
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