2222#include < QPainter>
2323#include < QStatusTipEvent>
2424
25+ #include < algorithm>
26+ #include < map>
27+
2528#define DECORATION_SIZE 54
2629#define NUM_ITEMS 5
2730
@@ -35,7 +38,7 @@ class TxViewDelegate : public QAbstractItemDelegate
3538 QAbstractItemDelegate (parent), unit (BitcoinUnits::BTC),
3639 platformStyle (_platformStyle)
3740 {
38-
41+ connect ( this , &TxViewDelegate::width_changed, this , &TxViewDelegate::sizeHintChanged);
3942 }
4043
4144 inline void paint (QPainter *painter, const QStyleOptionViewItem &option,
@@ -68,13 +71,15 @@ class TxViewDelegate : public QAbstractItemDelegate
6871
6972 painter->setPen (foreground);
7073 QRect boundingRect;
71- painter->drawText (addressRect, Qt::AlignLeft|Qt::AlignVCenter, address, &boundingRect);
74+ painter->drawText (addressRect, Qt::AlignLeft | Qt::AlignVCenter, address, &boundingRect);
75+ int address_rect_min_width = boundingRect.width ();
7276
7377 if (index.data (TransactionTableModel::WatchonlyRole).toBool ())
7478 {
7579 QIcon iconWatchonly = qvariant_cast<QIcon>(index.data (TransactionTableModel::WatchonlyDecorationRole));
7680 QRect watchonlyRect (boundingRect.right () + 5 , mainRect.top ()+ypad+halfheight, 16 , halfheight);
7781 iconWatchonly.paint (painter, watchonlyRect);
82+ address_rect_min_width += 5 + watchonlyRect.width ();
7883 }
7984
8085 if (amount < 0 )
@@ -95,23 +100,42 @@ class TxViewDelegate : public QAbstractItemDelegate
95100 {
96101 amountText = QString (" [" ) + amountText + QString (" ]" );
97102 }
98- painter->drawText (amountRect, Qt::AlignRight|Qt::AlignVCenter, amountText);
103+
104+ QRect amount_bounding_rect;
105+ painter->drawText (amountRect, Qt::AlignRight | Qt::AlignVCenter, amountText, &amount_bounding_rect);
99106
100107 painter->setPen (option.palette .color (QPalette::Text));
101- painter->drawText (amountRect, Qt::AlignLeft|Qt::AlignVCenter, GUIUtil::dateTimeStr (date));
108+ QRect date_bounding_rect;
109+ painter->drawText (amountRect, Qt::AlignLeft | Qt::AlignVCenter, GUIUtil::dateTimeStr (date), &date_bounding_rect);
110+
111+ const int minimum_width = std::max (address_rect_min_width, amount_bounding_rect.width () + date_bounding_rect.width ());
112+ const auto search = m_minimum_width.find (index.row ());
113+ if (search == m_minimum_width.end () || search->second != minimum_width) {
114+ m_minimum_width[index.row ()] = minimum_width;
115+ Q_EMIT width_changed (index);
116+ }
102117
103118 painter->restore ();
104119 }
105120
106121 inline QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const override
107122 {
108- return QSize (DECORATION_SIZE, DECORATION_SIZE);
123+ const auto search = m_minimum_width.find (index.row ());
124+ const int minimum_text_width = search == m_minimum_width.end () ? 0 : search->second ;
125+ return {DECORATION_SIZE + 8 + minimum_text_width, DECORATION_SIZE};
109126 }
110127
111128 int unit;
112- const PlatformStyle *platformStyle;
113129
130+ Q_SIGNALS:
131+ // ! An intermediate signal for emitting from the `paint() const` member function.
132+ void width_changed (const QModelIndex& index) const ;
133+
134+ private:
135+ const PlatformStyle* platformStyle;
136+ mutable std::map<int , int > m_minimum_width;
114137};
138+
115139#include < qt/overviewpage.moc>
116140
117141OverviewPage::OverviewPage (const PlatformStyle *platformStyle, QWidget *parent) :
0 commit comments