@@ -37,6 +37,9 @@ TransactionView::TransactionView(QWidget *parent)
37
37
, transactionProxyModel(nullptr )
38
38
, transactionView(nullptr )
39
39
, searchWidgetIconAction(new QAction())
40
+ , m_table_column_sizes({23 , 120 , 120 , 400 , 100 })
41
+ , m_init_column_sizes_set(false )
42
+ , m_resize_columns_in_progress(false )
40
43
{
41
44
setContentsMargins (0 , 0 , 0 , 0 );
42
45
@@ -110,7 +113,7 @@ TransactionView::TransactionView(QWidget *parent)
110
113
view->horizontalHeader ()->setHighlightSections (false );
111
114
transactionView = view;
112
115
113
- QVBoxLayout * tableViewLayout = new QVBoxLayout ();
116
+ QVBoxLayout* tableViewLayout = new QVBoxLayout ();
114
117
tableViewLayout->setContentsMargins (9 , 9 , 9 , 9 );
115
118
QFrame *tableViewFrame = new QFrame (this );
116
119
tableViewFrame->setObjectName (" historyTableFrame" );
@@ -181,16 +184,8 @@ void TransactionView::setModel(WalletModel *model)
181
184
transactionView->sortByColumn (TransactionTableModel::Date, Qt::DescendingOrder);
182
185
transactionView->verticalHeader ()->hide ();
183
186
184
- transactionView->horizontalHeader ()->resizeSection (
185
- TransactionTableModel::Status, 23 );
186
- transactionView->horizontalHeader ()->resizeSection (
187
- TransactionTableModel::Date, 120 );
188
- transactionView->horizontalHeader ()->resizeSection (
189
- TransactionTableModel::Type, 120 );
190
- transactionView->horizontalHeader ()->setSectionResizeMode (
191
- TransactionTableModel::ToAddress, QHeaderView::Stretch);
192
- transactionView->horizontalHeader ()->resizeSection (
193
- TransactionTableModel::Amount, 100 );
187
+ connect (transactionView->horizontalHeader (), &QHeaderView::sectionResized,
188
+ this , &TransactionView::txnViewSectionResized);
194
189
}
195
190
196
191
if (model && model->getOptionsModel ()) {
@@ -454,3 +449,79 @@ void TransactionView::updateIcons(const QString& theme)
454
449
{
455
450
searchWidgetIconAction->setIcon (QIcon (" :/icons/" + theme + " _search" ));
456
451
}
452
+
453
+ void TransactionView::resizeTableColumns (const bool & neighbor_pair_adjust, const int & index,
454
+ const int & old_size, const int & new_size)
455
+ {
456
+ // This prevents unwanted recursion to here from txnViewSectionResized.
457
+ m_resize_columns_in_progress = true ;
458
+
459
+ if (!model) {
460
+ m_resize_columns_in_progress = false ;
461
+
462
+ return ;
463
+ }
464
+
465
+ if (!m_init_column_sizes_set) {
466
+ for (int i = 0 ; i < (int ) m_table_column_sizes.size (); ++i) {
467
+ transactionView->horizontalHeader ()->resizeSection (i, m_table_column_sizes[i]);
468
+ }
469
+
470
+ m_init_column_sizes_set = true ;
471
+ m_resize_columns_in_progress = false ;
472
+
473
+ return ;
474
+ }
475
+
476
+ if (neighbor_pair_adjust) {
477
+ if (index != TransactionTableModel::all_ColumnIndex.size () - 1 ) {
478
+ int neighbor_section_size = transactionView->horizontalHeader ()->sectionSize (index + 1 );
479
+
480
+ transactionView->horizontalHeader ()->resizeSection (
481
+ index + 1 , neighbor_section_size + old_size - new_size);
482
+ } else {
483
+ // Do not allow the last column to be resized because their is no adjoining neighbor to the right
484
+ // and we are maintaining the total width fixed to the size of the containing frame.
485
+ transactionView->horizontalHeader ()->resizeSection (index , old_size);
486
+ }
487
+
488
+ m_resize_columns_in_progress = false ;
489
+
490
+ return ;
491
+ }
492
+
493
+ // This is the proportional resize case when the window is resized or the history icon button is pressed.
494
+ const int width = transactionView->horizontalHeader ()->width () - 5 ;
495
+
496
+ int orig_header_width = 0 ;
497
+
498
+ for (const auto & iter : TransactionTableModel::all_ColumnIndex) {
499
+ orig_header_width += transactionView->horizontalHeader ()->sectionSize (iter);
500
+ }
501
+
502
+ if (!width || !orig_header_width) return ;
503
+
504
+ for (const auto & iter : TransactionTableModel::all_ColumnIndex) {
505
+ int section_size = transactionView->horizontalHeader ()->sectionSize (iter);
506
+
507
+ transactionView->horizontalHeader ()->resizeSection (
508
+ iter, section_size * width / orig_header_width);
509
+ }
510
+
511
+ m_resize_columns_in_progress = false ;
512
+ }
513
+
514
+ void TransactionView::resizeEvent (QResizeEvent *event)
515
+ {
516
+ resizeTableColumns ();
517
+
518
+ QWidget::resizeEvent (event);
519
+ }
520
+
521
+ void TransactionView::txnViewSectionResized (int index, int old_size, int new_size)
522
+ {
523
+ // Avoid implicit recursion between resizeTableColumns and txnViewSectionResized
524
+ if (m_resize_columns_in_progress) return ;
525
+
526
+ resizeTableColumns (true , index , old_size, new_size);
527
+ }
0 commit comments