diff --git a/src/shared/Modules/OutgoingMessagesViewer/OutgoingMessagesViewerModule.cpp b/src/shared/Modules/OutgoingMessagesViewer/OutgoingMessagesViewerModule.cpp index b6f231d9f242a83ca4a0a6ea2c0af63787d647f1..82798be7f5a74eff94a7949a244c40116bffe0cb 100644 --- a/src/shared/Modules/OutgoingMessagesViewer/OutgoingMessagesViewerModule.cpp +++ b/src/shared/Modules/OutgoingMessagesViewer/OutgoingMessagesViewerModule.cpp @@ -126,6 +126,11 @@ void OutgoingMessagesViewerModule::setupUi() // Disable items selection table->setSelectionMode(QAbstractItemView::NoSelection); + // Set a fixed row height + QHeaderView* verticalHeader = table->verticalHeader(); + verticalHeader->setSectionResizeMode(QHeaderView::Fixed); + verticalHeader->setDefaultSectionSize(rowHeight); + setLayout(outerLayout); } @@ -166,34 +171,26 @@ void OutgoingMessagesViewerModule::customContextMenuActionSetup() void OutgoingMessagesViewerModule::resizeEvent(QResizeEvent* event) { - if (table->rowCount() == 0) - { - return; - } - int totalHeight = table->viewport()->height(); - int contentHeight = table->rowCount() * table->rowHeight(0); + int contentHeight = table->rowCount() * rowHeight; if (contentHeight <= totalHeight) { // Calculate how many rows can fit in the available space - int rowsToAdd = (totalHeight - contentHeight) / table->rowHeight(0); + int rowsToAdd = (totalHeight - contentHeight) / rowHeight; // Calculate how many messages are available and not shown int rowsAvailable = messages.count() - table->rowCount(); // Add rows to fill the available space for (int i = 0; i < std::min(rowsToAdd, rowsAvailable); i++) - { addMessageToTable(messages.at(table->rowCount()), table->rowCount()); - } } else { // Calculate how many rows need to be removed - int rowsToRemove = - (contentHeight - totalHeight) / table->rowHeight(0) + 1; + int rowsToRemove = (contentHeight - totalHeight) / rowHeight + 1; // Remove rows that don't fit int newRowCount = table->rowCount() - rowsToRemove; diff --git a/src/shared/Modules/OutgoingMessagesViewer/OutgoingMessagesViewerModule.h b/src/shared/Modules/OutgoingMessagesViewer/OutgoingMessagesViewerModule.h index 7235f1096e2027bae04bcc3560042ae252fdddc6..a3da97f9e9e8de2a40c11c1c5adcb17c0e98dc4b 100644 --- a/src/shared/Modules/OutgoingMessagesViewer/OutgoingMessagesViewerModule.h +++ b/src/shared/Modules/OutgoingMessagesViewer/OutgoingMessagesViewerModule.h @@ -63,4 +63,6 @@ private: int maxListSize = 20; int timerPeriod = 1000; // [ms] + + const int rowHeight = 30; // [px] };