The window lags while resizing if there are too many checkboxes.
-
Hello!
I made a window in Qt 6.9, the window has got two tabs one called "Selector" and the other "Logs".
Selector:
Logs:
As you see the "Selector" has a lot of checkboxes and the "Logs" tab does not, well, when in the "Selector" tab the window lags while resizing but in the "Logs" tab the window resize is smooth.
How can I make the resize smooth when in the "Selector" tab?
Thanks!
-
Hi and welcome to devnet,
How are you generating these checkboxes ?
Do you have a reimplemented resizeEvent function ? -
Hi and welcome to devnet,
How are you generating these checkboxes ?
Do you have a reimplemented resizeEvent function ?@SGaist I do not have a reimplemented resizeEvent function, this is how I create the checkboxes:
// Paths Group QGroupBox* pathsGroup = new QGroupBox("Paths"); QVBoxLayout* pathsLayout = new QVBoxLayout; QPushButton* selectAllPaths = new QPushButton("Select All Paths"); QPushButton* deselectAllPaths = new QPushButton("Deselect All Paths"); pathsLayout->addWidget(selectAllPaths); pathsLayout->addWidget(deselectAllPaths); QList<QCheckBox*> pathCheckboxes; for (const QString& s : paths) { auto cb = new QCheckBox(s); pathCheckboxes.append(cb); pathsLayout->addWidget(cb); } pathsLayout->addStretch(); pathsGroup->setLayout(pathsLayout); // Registry Keys Group QGroupBox* registryGroup = new QGroupBox("Registry Keys"); QVBoxLayout* registryLayout = new QVBoxLayout; QPushButton* selectAllRegistry = new QPushButton("Select All Keys"); QPushButton* deselectAllRegistry = new QPushButton("Deselect All Keys"); registryLayout->addWidget(selectAllRegistry); registryLayout->addWidget(deselectAllRegistry); QList<QCheckBox*> registryCheckboxes; for (const QString& s : registryKeys) { auto cb = new QCheckBox(s); registryCheckboxes.append(cb); registryLayout->addWidget(cb); } registryLayout->addStretch(); registryGroup->setLayout(registryLayout);
-
If those QStringLists paths and registrykeys do not change during the run of your app, consider moving the creation code out of your reiimplemented resizeEvent function, say to a function that's called at the start of your app. Then the resizing will be smoother.
-
If those QStringLists paths and registrykeys do not change during the run of your app, consider moving the creation code out of your reiimplemented resizeEvent function, say to a function that's called at the start of your app. Then the resizing will be smoother.
@hskoglund said in The window lags while resizing if there are too many checkboxes.:
consider moving the creation code out of your reiimplemented resizeEvent function
But @3xotic stated that it's not inside
resizeEvent
.@3xotic Do you update something else on resize? Do you repaint manually somewhere?
Usually it should not lag when resizing that few widgets... -
This post is deleted!
-
I'm gonna speak in generalities here...the widgets in a Qt application form a tree structure where they have children and usually a single parent widget. When you change an entity in the tree, all of its children need to be updated as well, so the closer you are to the trunk, the more background processing it requires. All Qt programmers need to keep this in mind and subjectively manage their UI design to balance functionality with processing overhead. I think you need to work out some UI strategies to minimize the overhead of large scale child widget updates in your design.
There are some experimental things to try but that's on you:
- horiz and vert scroll panel as parent of checkbox list
- custom widget design
- get rid of checkbox list in favor of a scrollable/collapsable tree-view
- add "submit" button to checkbox list and no doing any checkbox processing until the button is pressed
-
@hskoglund said in The window lags while resizing if there are too many checkboxes.:
consider moving the creation code out of your reiimplemented resizeEvent function
But @3xotic stated that it's not inside
resizeEvent
.@3xotic Do you update something else on resize? Do you repaint manually somewhere?
Usually it should not lag when resizing that few widgets...@Pl45m4 I do not update something else on resize and do not repaint manually somewhere (or so I think). Full code:
QApplication app(argc, argv); QWidget window; window.setWindowTitle("Adobe Leftovers Remover"); window.resize(1000, 800); window.setFixedSize(window.size()); // Make the window non-resizable QVBoxLayout* mainLayout = new QVBoxLayout(&window); QTabWidget* tabs = new QTabWidget; // Cleanup Tab QWidget* cleanupTab = new QWidget; QVBoxLayout* cleanupLayout = new QVBoxLayout(cleanupTab); QHBoxLayout* groups = new QHBoxLayout; // Paths Group QGroupBox* pathsGroup = new QGroupBox("Paths"); QVBoxLayout* pathsLayout = new QVBoxLayout; QPushButton* selectAllPaths = new QPushButton("Select All Paths"); QPushButton* deselectAllPaths = new QPushButton("Deselect All Paths"); pathsLayout->addWidget(selectAllPaths); pathsLayout->addWidget(deselectAllPaths); QList<QCheckBox*> pathCheckboxes; for (const QString& s : paths) { auto cb = new QCheckBox(s); pathCheckboxes.append(cb); pathsLayout->addWidget(cb); } pathsLayout->addStretch(); pathsGroup->setLayout(pathsLayout); // Registry Keys Group QGroupBox* registryGroup = new QGroupBox("Registry Keys"); QVBoxLayout* registryLayout = new QVBoxLayout; QPushButton* selectAllRegistry = new QPushButton("Select All Keys"); QPushButton* deselectAllRegistry = new QPushButton("Deselect All Keys"); registryLayout->addWidget(selectAllRegistry); registryLayout->addWidget(deselectAllRegistry); QList<QCheckBox*> registryCheckboxes; for (const QString& s : registryKeys) { auto cb = new QCheckBox(s); registryCheckboxes.append(cb); registryLayout->addWidget(cb); } registryLayout->addStretch(); registryGroup->setLayout(registryLayout); groups->addWidget(pathsGroup); groups->addWidget(registryGroup); cleanupLayout->addLayout(groups); QPushButton* deleteButton = new QPushButton("Delete Selected"); cleanupLayout->addWidget(deleteButton); // Logs Tab QWidget* logsTab = new QWidget; QVBoxLayout* logsLayout = new QVBoxLayout(logsTab); QTextEdit* logView = new QTextEdit; logView->setReadOnly(true); logsLayout->addWidget(logView); tabs->addTab(cleanupTab, "Cleanup"); tabs->addTab(logsTab, "Logs"); // Progress Bar QProgressBar* progress = new QProgressBar; progress->setValue(0); mainLayout->addWidget(tabs); mainLayout->addWidget(progress);