View Issue Details

IDProjectCategoryView StatusLast Update
0018042ScribusGeneralpublic2026-11-06 01:17
Reporterlchongv Assigned Tocbradney  
PrioritylowSeveritytweakReproducibilityalways
Status resolvedResolutionfixed 
PlatformArchOSLinux 
Fixed in Version1.7.5.svn 
Summary0018042: Pages palette: typing in a text frame freezes for about 2 s per key
DescriptionContext

I was editing a very large and complex document, set in a typeface with twenty variations per glyph. Scribus's performance collapsed with it, and editing directly on the canvas became impossible. That led to another idea: editing the texts in a browser, simultaneously, from computers on the same network, as in a newsroom. That will be for later patches. For now I found that the performance problem came from redrawing the thumbnails. Turning them off made it go away, but what good is a feature you cannot use? That is why I propose this patch. I hope it is useful to you. Thank you.


Steps To ReproduceEditing text in a text frame on a large document freezes the canvas for about 2 seconds per key. The cause is the Pages palette: every key released in a text frame calls ScribusDoc::changedPagePreview(), and half a second later the palette redraws a thumbnail of every page (ScribusView::PagesToPixmap(..., -1, ...)). It does this even when the palette is closed.

Measured on a 24-page newspaper document, offscreen, with real key events:
- before: about 1.8 to 2 s of blocked event loop per key;
- after patches 1 to 4: about 45 to 53 ms per key, with the palette open or closed.
Additional InformationWhat the four patches do

1. Pages palette: do not draw page thumbnails while the palette is hidden. The update is remembered and drawn in showEvent().
2. Pages palette: redraw thumbnails once changes pause. A single-shot 1 s timer is restarted by each change, so nothing is drawn while the user keeps typing.
3. Pages palette: in edit mode, redraw only the pages of the edited item. Leaving edit mode redraws all pages.
4. Edit mode: cursor and modifier keys do not request a page preview update.

Patches

- 0001-pages-palette-skip-thumbnails-while-hidden.patch
- 0002-pages-palette-redraw-after-changes-pause.patch (after 0001)
- 0003-pages-palette-redraw-only-edited-pages.patch (after 0002)
- 0004-canvas-edit-no-page-preview-for-cursor-keys.patch (after 0003)

Apply from the top of the trunk checkout, in order, base revision 27914:
    patch -Np0 < 0001-....patch (and so on, 0001 to 0004)

Testing

- The four patches apply in order, with no fuzz or offset, to a clean r27914 (and r27903).
- Built on Arch Linux with Qt 6 (package scribus-svn-perf 27914-1, built from these exact patches) together with the other requests; no new compiler warnings, also with -Wall -Wextra on the touched files.
- Offscreen runs with QTest key events: the per-key timings above.
- Not yet checked: that the thumbnails match a full redraw pixel by pixel after every kind of edit. Reviewers should look at this.

Known limits

- Thumbnails of pages not touched by the edit are updated when the user leaves edit mode, not while typing.
- Patch 3 relies on the edited item's page chain (PageItem::OwnPage, firstInChain/nextInChain). Items that are not on any page fall back to a full redraw.

Notes for the maintainers
- Each patch starts with its commit message. Line endings of the touched files are unchanged (pagepalette_pages.* and canvasmode_edit.cpp use CRLF).
Tags#patch_is_ready
PatchYes

Activities

lchongv

2026-10-26 00:13

reporter   ~0054613

Here are the patches

lchongv

2026-10-26 01:21

reporter   ~0054614

I'm so clueless. Please excuse my clumsiness in uploading the patches. Here they are.
0001-pages-palette-skip-thumbnails-while-hidden.patch (3,358 bytes)   
Subject: [PATCH 1/4] Pages palette: do not draw page thumbnails while the palette is hidden

Every key released in a text frame calls ScribusDoc::changedPagePreview(). Half a second later the
Pages palette redraws a thumbnail of EVERY page (ScribusView::PagesToPixmap(..., -1, ...)), even when
the palette is closed. On a 24-page newspaper this blocks the event loop ~1.8 s per keystroke.
While hidden, only remember that thumbnails are owed (m_pagePreviewNeeded) and draw them in showEvent().
The flag is cleared only where all pages are actually drawn (full redraw, rebuildPages()), so an update
skipped for any reason is retried on the next show or change.

Index: scribus/ui/pagepalette_pages.cpp
===================================================================
--- scribus/ui/pagepalette_pages.cpp	(revision 27914)
+++ scribus/ui/pagepalette_pages.cpp	(working copy)
@@ -198,6 +198,13 @@ void PagePalette_Pages::pageView_updatePagePreview()
 		return;
 	}
 
+	if (!isVisible())
+	{
+		m_pagePreviewNeeded = true;
+		m_pagePreviewUpdatePending = true;
+		return;
+	}
+
 	if (pageViewWidget->pageGrid()->rowHeight() == PageGrid::Small)
 	{
 		for (int i = 0; i < currView->m_doc->DocPages.count(); ++i)
@@ -217,6 +224,7 @@ void PagePalette_Pages::pageView_updatePagePreview()
 	{
 		PageToPixmapFlags flags = Pixmap_DrawFrame | Pixmap_DrawBackground | Pixmap_DontReloadImages | Pixmap_NoCanvasModeChange | Pixmap_NoCMSSettingsChange;
 		QMap<int, QImage> previews = currView->PagesToPixmap(pageViewWidget->pageGrid()->pageHeight() * devicePixelRatio(), -1, flags);
+		m_pagePreviewNeeded = false;
 
 		for (int i = 0; i < currView->m_doc->DocPages.count(); ++i)
 		{
@@ -247,6 +255,13 @@ void PagePalette_Pages::updatePageGrid()
 
 void PagePalette_Pages::updatePagePreview()
 {
+	// Drawing every page is slow: while the palette is hidden, draw them when it is shown
+	if (!isVisible())
+	{
+		m_pagePreviewNeeded = true;
+		return;
+	}
+
 	if (currView == nullptr || pageViewWidget->pageGrid()->pageList.empty())
 	{
 		m_pagePreviewUpdatePending = true;
@@ -447,6 +462,8 @@ void PagePalette_Pages::rebuildPages()
 	pageViewWidget->pageGrid()->update();
 
 	m_pagePreviewUpdatePending = true;
+	// All pages were just drawn
+	m_pagePreviewNeeded = false;
 
 	if (currView != nullptr)
 	{
@@ -527,6 +544,14 @@ void PagePalette_Pages::changeEvent(QEvent *e)
 	QWidget::changeEvent(e);
 }
 
+void PagePalette_Pages::showEvent(QShowEvent *e)
+{
+	QWidget::showEvent(e);
+	// The flag is cleared once all pages are drawn, so a skipped update is retried
+	if (m_pagePreviewNeeded)
+		updatePagePreview();
+}
+
 void PagePalette_Pages::iconSetChange()
 {
 	IconManager& iconManager = IconManager::instance();
Index: scribus/ui/pagepalette_pages.h
===================================================================
--- scribus/ui/pagepalette_pages.h	(revision 27914)
+++ scribus/ui/pagepalette_pages.h	(working copy)
@@ -69,10 +69,12 @@ protected:
 	ScribusView       *currView { nullptr};
 	ScribusMainWindow *m_scMW { nullptr};
 	bool m_pagePreviewUpdatePending {true};
+	bool m_pagePreviewNeeded { false };
 
 //	QPixmap createPagePreview(const QPixmap& pixin, QSize size);
 
 	void changeEvent(QEvent *e) override;
+	void showEvent(QShowEvent *e) override;
 };
 
 #endif // SEITENPAL_H
0002-pages-palette-redraw-after-changes-pause.patch (2,507 bytes)   
Subject: [PATCH 2/4] Pages palette: redraw thumbnails once changes pause, not while typing

The 500 ms single shot only throttles: while typing, all thumbnails are still redrawn every
~0.5 s plus the time the redraw takes. A member single-shot QTimer (1 s) is restarted by every change,
so nothing is drawn while changes keep coming. m_pagePreviewUpdatePending is no longer cleared when
the timer starts, since restarting the timer already coalesces the requests; the flag still blocks
requests while rebuildPages() runs.

Index: scribus/ui/pagepalette_pages.cpp
===================================================================
--- scribus/ui/pagepalette_pages.cpp	(revision 27914)
+++ scribus/ui/pagepalette_pages.cpp	(working copy)
@@ -81,6 +81,11 @@ PagePalette_Pages::PagePalette_Pages(QWidget *parent)
 	connect( buttonPageDuplicate, SIGNAL(clicked()), this, SLOT(duplicatePage()) );
 	connect( buttonPageMove, SIGNAL(clicked()), this, SLOT(movePage()) );
 
+	// Every change restarts the timer: previews are drawn once changes pause
+	m_previewTimer.setSingleShot(true);
+	m_previewTimer.setInterval(1000);
+	connect(&m_previewTimer, &QTimer::timeout, this, &PagePalette_Pages::pageView_updatePagePreview);
+
 	connect(this, SIGNAL(gotoPage(int)), m_scMW, SLOT(selectPagesFromOutlines(int)));
 }
 
@@ -278,13 +283,8 @@ void PagePalette_Pages::updatePagePreview()
 		(currView->updatesEnabled()) &&
 		(currView->m_doc->DocPages.count() == pageViewWidget->pageGrid()->pageList.count()))
 	{
-		m_pagePreviewUpdatePending = false;
-
-		// limit preview update to 1 refresh event each 500ms
-		QTimer::singleShot(500, this, [this]()
-		{
-			pageView_updatePagePreview();
-		});
+		// restarts if already running: nothing is drawn while changes keep coming
+		m_previewTimer.start();
 	}
 }
 
Index: scribus/ui/pagepalette_pages.h
===================================================================
--- scribus/ui/pagepalette_pages.h	(revision 27914)
+++ scribus/ui/pagepalette_pages.h	(working copy)
@@ -12,6 +12,7 @@ for which a new license (GPL+exception) is in place.
 #include <QLayout>
 #include <QPixmap>
 #include <QSplitter>
+#include <QTimer>
 #include <QVBoxLayout>
 
 #include "ui_pagepalette_pagesbase.h"
@@ -70,6 +71,7 @@ protected:
 	ScribusMainWindow *m_scMW { nullptr};
 	bool m_pagePreviewUpdatePending {true};
 	bool m_pagePreviewNeeded { false };
+	QTimer m_previewTimer;
 
 //	QPixmap createPagePreview(const QPixmap& pixin, QSize size);
 
0003-pages-palette-redraw-only-edited-pages.patch (5,308 bytes)   
Subject: [PATCH 3/4] Pages palette: in edit mode, redraw only the pages of the edited item

While one item is edited (modeEdit, not in master page mode), only the pages holding the item and the
frames linked to it (PageItem::OwnPage along the chain) are redrawn. m_previewStale records that other
thumbnails may be out of date; leaving edit mode (AppModeChanged) then redraws all pages. Items with no
page (OwnPage < 0) fall back to a full redraw. rebuildPages() clears the flag, which also covers
document switches that set appMode directly.

Index: scribus/ui/pagepalette_pages.cpp
===================================================================
--- scribus/ui/pagepalette_pages.cpp	(revision 27914)
+++ scribus/ui/pagepalette_pages.cpp	(working copy)
@@ -20,18 +20,23 @@ for which a new license (GPL+exception) is in place.
 #include <QPainter>
 #include <QRegularExpression>
 
+#include "appmodehelper.h"
+#include "appmodes.h"
 #include "commonstrings.h"
 #include "iconmanager.h"
+#include "pageitem.h"
 #include "ui/widgets/pagelayout.h"
 #include "pagepalette_pages.h"
 #include "pagepalette_widgets.h"
 #include "prefsmanager.h"
 #include "qobjectdefs.h"
 #include "scpage.h"
+#include "scribus.h"
 #include "scribusapp.h"
 #include "scribuscore.h"
 #include "scribusdoc.h"
 #include "scribusview.h"
+#include "selection.h"
 
 PagePalette_Pages::PagePalette_Pages(QWidget *parent)
 	: QWidget(parent)
@@ -85,6 +90,7 @@ PagePalette_Pages::PagePalette_Pages(QWidget *parent)
 	m_previewTimer.setSingleShot(true);
 	m_previewTimer.setInterval(1000);
 	connect(&m_previewTimer, &QTimer::timeout, this, &PagePalette_Pages::pageView_updatePagePreview);
+	connect(m_scMW->appModeHelper, SIGNAL(AppModeChanged(int,int)), this, SLOT(handleAppModeChanged(int,int)));
 
 	connect(this, SIGNAL(gotoPage(int)), m_scMW, SLOT(selectPagesFromOutlines(int)));
 }
@@ -206,6 +212,7 @@ void PagePalette_Pages::pageView_updatePagePreview()
 	if (!isVisible())
 	{
 		m_pagePreviewNeeded = true;
+		m_previewStale = true;
 		m_pagePreviewUpdatePending = true;
 		return;
 	}
@@ -228,8 +235,21 @@ void PagePalette_Pages::pageView_updatePagePreview()
 	else
 	{
 		PageToPixmapFlags flags = Pixmap_DrawFrame | Pixmap_DrawBackground | Pixmap_DontReloadImages | Pixmap_NoCanvasModeChange | Pixmap_NoCMSSettingsChange;
-		QMap<int, QImage> previews = currView->PagesToPixmap(pageViewWidget->pageGrid()->pageHeight() * devicePixelRatio(), -1, flags);
-		m_pagePreviewNeeded = false;
+		int previewHeight = pageViewWidget->pageGrid()->pageHeight() * devicePixelRatio();
+		QList<int> pageNrs = editedPages();
+		QMap<int, QImage> previews;
+		if (pageNrs.isEmpty())
+		{
+			previews = currView->PagesToPixmap(previewHeight, -1, flags);
+			m_previewStale = false;
+			m_pagePreviewNeeded = false;
+		}
+		else
+		{
+			for (int pageNr : pageNrs)
+				previews.insert(currView->PagesToPixmap(previewHeight, pageNr, flags));
+			m_previewStale = true;
+		}
 
 		for (int i = 0; i < currView->m_doc->DocPages.count(); ++i)
 		{
@@ -264,6 +284,7 @@ void PagePalette_Pages::updatePagePreview()
 	if (!isVisible())
 	{
 		m_pagePreviewNeeded = true;
+		m_previewStale = true;
 		return;
 	}
 
@@ -464,6 +485,7 @@ void PagePalette_Pages::rebuildPages()
 	m_pagePreviewUpdatePending = true;
 	// All pages were just drawn
 	m_pagePreviewNeeded = false;
+	m_previewStale = false;
 
 	if (currView != nullptr)
 	{
@@ -552,6 +574,28 @@ void PagePalette_Pages::showEvent(QShowEvent *e)
 		updatePagePreview();
 }
 
+void PagePalette_Pages::handleAppModeChanged(int oldMode, int newMode)
+{
+	// Leaving edit mode: pages other than the edited one may be out of date
+	if (oldMode == modeEdit && newMode != modeEdit && m_previewStale)
+		updatePagePreview();
+}
+
+QList<int> PagePalette_Pages::editedPages() const
+{
+	// While an item is edited, only the pages holding its frames change
+	QList<int> pageNrs;
+	ScribusDoc* doc = currView->m_doc;
+	if (doc->appMode != modeEdit || doc->masterPageMode() || doc->m_Selection->count() != 1)
+		return pageNrs;
+	for (PageItem* item = doc->m_Selection->itemAt(0)->firstInChain(); item != nullptr; item = item->nextInChain())
+	{
+		if (item->OwnPage >= 0 && !pageNrs.contains(item->OwnPage))
+			pageNrs.append(item->OwnPage);
+	}
+	return pageNrs;
+}
+
 void PagePalette_Pages::iconSetChange()
 {
 	IconManager& iconManager = IconManager::instance();
Index: scribus/ui/pagepalette_pages.h
===================================================================
--- scribus/ui/pagepalette_pages.h	(revision 27914)
+++ scribus/ui/pagepalette_pages.h	(working copy)
@@ -55,6 +55,7 @@ private slots:
 	void pageView_gotoPage(int pageID, int b);
 	void pageView_deletePage(int pageIndex);
 	void pageView_updatePagePreview();
+	void handleAppModeChanged(int oldMode, int newMode);
 
 	void newPage();
 	void duplicatePage();
@@ -71,8 +72,11 @@ protected:
 	ScribusMainWindow *m_scMW { nullptr};
 	bool m_pagePreviewUpdatePending {true};
 	bool m_pagePreviewNeeded { false };
+	bool m_previewStale { false };
 	QTimer m_previewTimer;
 
+	QList<int> editedPages() const;
+
 //	QPixmap createPagePreview(const QPixmap& pixin, QSize size);
 
 	void changeEvent(QEvent *e) override;
0004-canvas-edit-no-page-preview-for-cursor-keys.patch (1,181 bytes)   
Subject: [PATCH 4/4] Edit mode: cursor and modifier keys do not request a page preview update

Arrow keys, Home/End, PageUp/PageDown and modifier keys (Shift, Ctrl, Alt, AltGr, Meta, Caps Lock)
change nothing on the page, but their key release called ScribusDoc::changedPagePreview() too.

Index: scribus/canvasmode_edit.cpp
===================================================================
--- scribus/canvasmode_edit.cpp	(revision 27914)
+++ scribus/canvasmode_edit.cpp	(working copy)
@@ -174,7 +174,28 @@ void CanvasMode_Edit::keyReleaseEvent(QKeyEvent *e)
 
 	if (currItem->isTextFrame())
 	{
-		m_doc->changedPagePreview();
+		switch (e->key())
+		{
+			// Moving the cursor or pressing a modifier changes nothing on the page
+			case Qt::Key_Left:
+			case Qt::Key_Right:
+			case Qt::Key_Up:
+			case Qt::Key_Down:
+			case Qt::Key_Home:
+			case Qt::Key_End:
+			case Qt::Key_PageUp:
+			case Qt::Key_PageDown:
+			case Qt::Key_Shift:
+			case Qt::Key_Control:
+			case Qt::Key_Alt:
+			case Qt::Key_AltGr:
+			case Qt::Key_Meta:
+			case Qt::Key_CapsLock:
+				break;
+			default:
+				m_doc->changedPagePreview();
+				break;
+		}
 	}
 
 }

cbradney

2026-11-05 20:21

administrator   ~0054659

Thank you, committed with some additional changes

lchongv

2026-11-06 01:17

reporter   ~0054660

thanks to all of you

Issue History

Date Modified Username Field Change
2026-10-26 00:11 lchongv New Issue
2026-10-26 00:11 lchongv Tag Attached: #patch_is_ready
2026-10-26 00:13 lchongv Note Added: 0054613
2026-10-26 00:13 lchongv File Added: 0001-pages-palette-skip-thumbnails-while-hidden.patch
2026-10-26 00:13 lchongv File Added: 0002-pages-palette-redraw-after-changes-pause.patch
2026-10-26 00:13 lchongv File Deleted: 0001-pages-palette-skip-thumbnails-while-hidden.patch
2026-10-26 00:14 lchongv File Deleted: 0002-pages-palette-redraw-after-changes-pause.patch
2026-10-26 01:21 lchongv Note Added: 0054614
2026-10-26 01:21 lchongv File Added: 0001-pages-palette-skip-thumbnails-while-hidden.patch
2026-10-26 01:21 lchongv File Added: 0002-pages-palette-redraw-after-changes-pause.patch
2026-10-26 01:21 lchongv File Added: 0003-pages-palette-redraw-only-edited-pages.patch
2026-10-26 01:21 lchongv File Added: 0004-canvas-edit-no-page-preview-for-cursor-keys.patch
2026-11-05 20:21 cbradney Assigned To => cbradney
2026-11-05 20:21 cbradney Status new => resolved
2026-11-05 20:21 cbradney Resolution open => fixed
2026-11-05 20:21 cbradney Fixed in Version => 1.7.5.svn
2026-11-05 20:21 cbradney Note Added: 0054659
2026-11-06 01:17 lchongv Note Added: 0054660