Skip to content

Commit 6b17aff

Browse files
Copilotxusheng6
andcommitted
Fix TTD Memory Widget + button positioning using setCornerWidget
Co-authored-by: xusheng6 <[email protected]>
1 parent bef0b8f commit 6b17aff

File tree

2 files changed

+11
-42
lines changed

2 files changed

+11
-42
lines changed

ui/ttdmemorywidget.cpp

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ limitations under the License.
2626
#include <QCheckBox>
2727
#include <QToolButton>
2828
#include <QPropertyAnimation>
29-
#include <QResizeEvent>
3029
#include <QFrame>
3130

3231
// ExpandableGroupBox implementation
@@ -715,46 +714,33 @@ void TTDMemoryWidget::setupUI()
715714

716715
QVBoxLayout* mainLayout = new QVBoxLayout(this);
717716

718-
// Create a horizontal layout to hold the tab widget and + button
719-
QWidget* tabContainer = new QWidget();
720-
m_tabLayout = new QHBoxLayout(tabContainer);
721-
m_tabLayout->setContentsMargins(0, 0, 0, 0);
722-
m_tabLayout->setSpacing(0);
723-
724717
// Tab widget setup
725-
m_tabWidget = new QTabWidget();
718+
m_tabWidget = new QTabWidget(this);
726719
m_tabWidget->setTabsClosable(true);
727720
connect(m_tabWidget, &QTabWidget::tabCloseRequested, this, &TTDMemoryWidget::closeTab);
728721

729-
// Create "+" button
730-
m_newTabButton = new QPushButton("+");
731-
m_newTabButton->setMaximumSize(25, 25);
732-
m_newTabButton->setMinimumSize(25, 25);
733-
m_newTabButton->setToolTip("Create new query tab");
734-
m_newTabButton->setStyleSheet("QPushButton { border: 1px solid #555; border-radius: 3px; margin-top: 2px; }");
735-
connect(m_newTabButton, &QPushButton::clicked, this, &TTDMemoryWidget::createNewTab);
722+
// Create "+" button as corner widget
723+
m_newTabButton = new QToolButton(m_tabWidget);
724+
m_newTabButton->setText("+");
725+
m_newTabButton->setAutoRaise(true);
726+
m_newTabButton->setToolTip("New tab");
727+
connect(m_newTabButton, &QToolButton::clicked, this, &TTDMemoryWidget::createNewTab);
736728

737-
// Add tab widget and button to horizontal layout
738-
m_tabLayout->addWidget(m_tabWidget);
739-
m_tabLayout->addWidget(m_newTabButton, 0, Qt::AlignTop);
729+
// Set the button as corner widget
730+
m_tabWidget->setCornerWidget(m_newTabButton, Qt::TopRightCorner);
740731

741-
mainLayout->addWidget(tabContainer);
732+
mainLayout->addWidget(m_tabWidget);
742733
setLayout(mainLayout);
743734

744735
// Create initial tab
745736
createNewTab();
746-
747-
// Update button position when tabs change
748-
connect(m_tabWidget, &QTabWidget::currentChanged, this, &TTDMemoryWidget::updateNewTabButtonPosition);
749-
connect(m_tabWidget, &QTabWidget::tabBarClicked, this, &TTDMemoryWidget::updateNewTabButtonPosition);
750737
}
751738

752739
void TTDMemoryWidget::createNewTab()
753740
{
754741
TTDMemoryQueryWidget* queryWidget = new TTDMemoryQueryWidget(this, m_data);
755742
int tabIndex = m_tabWidget->addTab(queryWidget, QString("Query %1").arg(m_tabWidget->count() + 1));
756743
m_tabWidget->setCurrentIndex(tabIndex);
757-
updateNewTabButtonPosition();
758744
}
759745

760746
void TTDMemoryWidget::closeTab(int index)
@@ -764,21 +750,9 @@ void TTDMemoryWidget::closeTab(int index)
764750
QWidget* widget = m_tabWidget->widget(index);
765751
m_tabWidget->removeTab(index);
766752
widget->deleteLater();
767-
updateNewTabButtonPosition();
768753
}
769754
}
770755

771-
void TTDMemoryWidget::updateNewTabButtonPosition()
772-
{
773-
// This will be called to adjust the button position if needed
774-
// For now, the horizontal layout should handle this automatically
775-
}
776-
777-
void TTDMemoryWidget::resizeEvent(QResizeEvent* event)
778-
{
779-
QWidget::resizeEvent(event);
780-
updateNewTabButtonPosition();
781-
}
782756

783757

784758
// TTDMemorySidebarWidget implementation

ui/ttdmemorywidget.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,15 @@ class TTDMemoryWidget : public QWidget
137137
private:
138138
BinaryViewRef m_data;
139139
DbgRef<DebuggerController> m_controller;
140-
QHBoxLayout* m_tabLayout;
141140
QTabWidget* m_tabWidget;
142-
QPushButton* m_newTabButton;
141+
QToolButton* m_newTabButton;
143142

144143
void setupUI();
145-
void updateNewTabButtonPosition();
146144

147145
public:
148146
TTDMemoryWidget(QWidget* parent, BinaryViewRef data);
149147
virtual ~TTDMemoryWidget();
150148

151-
protected:
152-
void resizeEvent(QResizeEvent* event) override;
153-
154149
private Q_SLOTS:
155150
void createNewTab();
156151
void closeTab(int index);

0 commit comments

Comments
 (0)