activate grid button and widget size
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user