Skip to content
Snippets Groups Projects
Commit b7d6fcbb authored by morkolai's avatar morkolai
Browse files

#96 WIP Prøvde å bruke TextEditWithSizeOfcontent

parent c8859675
No related branches found
No related tags found
1 merge request!57#96 Telefonliste & Fiks til høyde på tabeller (rundt oppløsning)
Pipeline #81866 failed
......@@ -149,6 +149,39 @@ class PhoneTable(QTableWidget):
return QSize(width, heigth)
class TextEditWithSizeOfContent(QTextEdit):
"""Custom QTextEdit subclass that grows to fit it's text."""
def __init__(self, *arg, **kwargs):
super(TextEditWithSizeOfContent, self).__init__(*arg, **kwargs)
self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
# self.setLineWrapMode(QTextEdit.NoWrap)
def sizeHint(self, h):
"""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(10, self.table.get_needed_size().width()))
size.setHeight(max(100, size.height()))
return size
def resizeEvent(self, event):
"""Update geometry before handling the resizeEvent.
See sources in module docstring.
Parameters
----------
event : QResizeEvent
event sent by Qt
"""
self.updateGeometry()
super(TextEditWithSizeOfContent, self).resizeEvent(event)
class ComponentsPopup(QDialog):
def __init__(self):
super().__init__()
......@@ -291,7 +324,7 @@ class PhonebookModule(ModuleBase, QWidget, metaclass=Meta):
self.layout.addWidget(self.table)
self.layout.addWidget(self.help_text)
self.layout.addLayout(self.buttons)
self.layout.setAlignment(Qt.AlignLeft)
self.layout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
self.setLayout(self.layout)
def __create_usage_help_text(self):
......@@ -303,26 +336,12 @@ class PhonebookModule(ModuleBase, QWidget, metaclass=Meta):
textfield belonding to the table
"""
txt = "Insert text here"
help_text = QTextEdit()
help_text = TextEditWithSizeOfContent()
help_text.setPlaceholderText(txt)
def resize_help_text():
help_text.setFixedWidth(self.table.get_needed_size().width())
L = len(help_text.toPlainText())
We = help_text.fontWeight()
Wi = self.table.get_needed_size().width()
foo = (L * We) / Wi
if foo < 30:
help_text.setFixedHeight(100)
else:
help_text.setFixedHeight(foo * 3.3)
resize_help_text()
# help_text.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
help_text.cursorPositionChanged.connect(lambda: resize_help_text())
help_text.cursorPositionChanged.connect(
lambda: (help_text.sizeHint(), help_text.adjustSize())
)
return help_text
......
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