Implement a replaceWidget helper function
This commit is contained in:
parent
bc335f1686
commit
da6b2b02f4
@ -24,7 +24,7 @@ from comicapi.genericmetadata import GenericMetadata
|
||||
from comicapi.issuestring import IssueString
|
||||
from comictaggerlib.coverimagewidget import CoverImageWidget
|
||||
from comictaggerlib.ctsettings import ct_ns
|
||||
from comictaggerlib.ui import ui_path
|
||||
from comictaggerlib.ui import qtutils, ui_path
|
||||
from comictaggerlib.ui.qtutils import new_web_view, reduce_widget_font_size
|
||||
from comictalker.comictalker import ComicTalker, TalkerError
|
||||
|
||||
@ -66,12 +66,7 @@ class IssueSelectionWindow(QtWidgets.QDialog):
|
||||
self.teDescription: QtWidgets.QWidget
|
||||
webengine = new_web_view(self)
|
||||
if webengine:
|
||||
self.teDescription.hide()
|
||||
self.teDescription.deleteLater()
|
||||
# I don't know how to replace teDescription, this is the result of teDescription.height() once rendered
|
||||
webengine.resize(webengine.width(), 141)
|
||||
self.splitter.addWidget(webengine)
|
||||
self.teDescription = webengine
|
||||
self.teDescription = qtutils.replaceWidget(self.splitter, self.teDescription, webengine)
|
||||
logger.info("successfully loaded QWebEngineView")
|
||||
else:
|
||||
logger.info("failed to open QWebEngineView")
|
||||
|
@ -33,7 +33,7 @@ from comictaggerlib.issueidentifier import IssueIdentifier
|
||||
from comictaggerlib.issueselectionwindow import IssueSelectionWindow
|
||||
from comictaggerlib.matchselectionwindow import MatchSelectionWindow
|
||||
from comictaggerlib.progresswindow import IDProgressWindow
|
||||
from comictaggerlib.ui import ui_path
|
||||
from comictaggerlib.ui import qtutils, ui_path
|
||||
from comictaggerlib.ui.qtutils import new_web_view, reduce_widget_font_size
|
||||
from comictalker.comictalker import ComicTalker, TalkerError
|
||||
|
||||
@ -127,12 +127,7 @@ class SeriesSelectionWindow(QtWidgets.QDialog):
|
||||
self.teDetails: QtWidgets.QWidget
|
||||
webengine = new_web_view(self)
|
||||
if webengine:
|
||||
self.teDetails.hide()
|
||||
self.teDetails.deleteLater()
|
||||
# I don't know how to replace teDetails, this is the result of teDetails.height() once rendered
|
||||
webengine.resize(webengine.width(), 141)
|
||||
self.splitter.addWidget(webengine)
|
||||
self.teDetails = webengine
|
||||
self.teDetails = qtutils.replaceWidget(self.splitter, self.teDetails, webengine)
|
||||
|
||||
reduce_widget_font_size(self.teDetails, 1)
|
||||
reduce_widget_font_size(self.twList)
|
||||
|
@ -215,3 +215,26 @@ if qt_available:
|
||||
widget.setPalette(inactive_palette[0])
|
||||
elif isinstance(widget, QtWidgets.QListWidget):
|
||||
widget.setMovement(QtWidgets.QListWidget.Static)
|
||||
|
||||
def replaceWidget(
|
||||
layout: QtWidgets.QLayout | QtWidgets.QSplitter, old_widget: QtWidgets.QWidget, new_widget: QtWidgets.QWidget
|
||||
) -> QtWidgets.QWidget:
|
||||
|
||||
if isinstance(layout, QtWidgets.QLayout):
|
||||
layout.replaceWidget(old_widget, new_widget)
|
||||
elif isinstance(layout, QtWidgets.QSplitter):
|
||||
layout.refresh()
|
||||
layout.replaceWidget(layout.indexOf(old_widget), new_widget)
|
||||
|
||||
new_widget.setBaseSize(old_widget.baseSize())
|
||||
new_widget.setSizeIncrement(old_widget.sizeIncrement())
|
||||
new_widget.setMinimumSize(old_widget.minimumSize())
|
||||
new_widget.setMaximumSize(old_widget.maximumSize())
|
||||
new_widget.setGeometry(old_widget.geometry())
|
||||
new_widget.setSizePolicy(old_widget.sizePolicy())
|
||||
|
||||
old_widget.hide()
|
||||
old_widget.deleteLater()
|
||||
# QSplitter has issues with replacing a widget before it's been first shown. Assume it should be visible
|
||||
new_widget.show()
|
||||
return new_widget
|
||||
|
Loading…
Reference in New Issue
Block a user