activate grid button and widget size

This commit is contained in:
AndreaRigoni
2026-03-17 22:56:56 +00:00
parent 553bb7fd61
commit 92a06f6274
7 changed files with 210 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
#include "vtkQViewport.h"
#include <QVBoxLayout>
#include <QResizeEvent>
#include <vtkAxesActor.h>
#include <vtkCamera.h>
@@ -17,6 +18,7 @@ QViewport::QViewport(QWidget* parent)
: QWidget(parent)
, Viewport()
, m_VtkWidget(nullptr)
, m_GridButton(nullptr)
{
// Build the layout zero margins so VTK fills the entire widget
auto* layout = new QVBoxLayout(this);
@@ -26,6 +28,36 @@ QViewport::QViewport(QWidget* parent)
m_VtkWidget = new QVTKOpenGLNativeWidget(this);
layout->addWidget(m_VtkWidget);
// Grid Toggle Button
m_GridButton = new QPushButton(m_VtkWidget);
m_GridButton->setText("#");
m_GridButton->setFixedSize(40, 40);
m_GridButton->setToolTip("Toggle Grid");
m_GridButton->setStyleSheet(
"QPushButton {"
" border-radius: 20px;" // Perfectly circular
" background-color: rgba(40, 40, 40, 180);"
" color: white;"
" font-size: 22px;"
" border: 1.5px solid rgba(255, 255, 255, 60);"
"}"
"QPushButton:hover {"
" background-color: rgba(70, 70, 70, 200);"
" border: 1.5px solid rgba(255, 255, 255, 100);"
"}"
"QPushButton:checked {"
" background-color: rgba(0, 120, 215, 200);" // Nice "active" blue
" color: white;"
" border: 1.5px solid rgba(255, 255, 255, 120);"
"}"
"QPushButton:pressed {"
" background-color: rgba(0, 90, 160, 220);"
"}"
);
m_GridButton->setCheckable(true);
m_GridButton->setChecked(true); // Grid is on by default
connect(m_GridButton, &QPushButton::clicked, this, &QViewport::onGridButtonClicked);
// After the Qt widget exists but before the first paint,
// attach the renderer and configure the pipeline.
SetupPipeline();
@@ -64,5 +96,22 @@ vtkRenderWindowInteractor* QViewport::GetInteractor()
return m_VtkWidget->renderWindow()->GetInteractor();
}
void QViewport::onGridButtonClicked()
{
SetGridVisible(m_GridButton->isChecked());
}
void QViewport::resizeEvent(QResizeEvent* event)
{
QWidget::resizeEvent(event);
if (m_GridButton) {
// Position under the gizmo (top-right corner).
// Standard CameraOrientationWidget is usually 150-180px.
int x = width() - m_GridButton->width() - 10;
int y = 160;
m_GridButton->move(x, y);
}
}
} // namespace Vtk
} // namespace uLib