Quote:
Originally Posted by capink
I wonder if it is possible to add an additional nested layout instead, right above the font row, something like this
|
That is in effect what I did.
I added 6 invisible rows above the font size line. Each row is a named label and a QBoxLayout. You can add widgets to that layout (default layout direction is vertical), or you can add a nested layout to do something more complicated. I did it this way so that the labels will line up with the existing ones. Why more than 1? So you can have multiple labels. Why 6? Felt like a nice number.
Here is an example, gui2.actions.show_template_tester.py. I used two of the 6 lines. The first is a label with a single QComboBox widget. The second is a label with an embedded grid layout.
Spoiler:
Code:
def show_template_editor(self, *args):
view = self.gui.current_view()
if view is not self.gui.library_view:
return error_dialog(self.gui, _('No template tester available'),
_('Template tester is not available for books '
'on the device.')).exec_()
rows = view.selectionModel().selectedRows()
if not rows:
return error_dialog(self.gui, _('No books selected'),
_('One book must be selected'), show=True)
if len(rows) > 1:
return error_dialog(self.gui, _('Selected multiple books'),
_('Only one book can be selected'), show=True)
index = rows[0]
if index.isValid():
db = view.model().db
t = TemplateDialog(self.gui, self.previous_text,
mi=db.get_metadata(index.row(), index_is_id=False, get_cover=False),
text_is_placeholder=self.first_time)
t.setWindowTitle(_('Template tester'))
#---- EXAMPLE STARTS HERE
t.user_label_1.setVisible(True)
t.user_label_1.setText('Example combo box:')
from PyQt5.Qt import QComboBox
box = QComboBox(t)
box.addItems(['one', 'two', 'three'])
t.user_layout_1.addWidget(box)
#----
t.user_label_2.setVisible(True)
t.user_label_2.setText('Example embedded layout:')
from PyQt5.Qt import QGridLayout, QLabel
gl = QGridLayout()
w1 = QLabel('Grid Row 0 Col 0')
gl.addWidget(w1, 0, 0)
w1 = QLabel('Grid Row 1 Col 1')
gl.addWidget(w1, 1, 1)
t.user_layout_2.addLayout(gl)
#---- EXAMPLE ENDS HERE
if t.exec_() == QDialog.DialogCode.Accepted:
self.previous_text = t.rule[1]
self.first_time = False