Add design prototype, some renamings.

This commit is contained in:
2025-12-22 21:27:20 +01:00
parent 4bd8f30a09
commit 03381ea705
20 changed files with 1219 additions and 159 deletions

View File

@@ -0,0 +1,198 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 18.0.1, 2025-12-22T19:04:55. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
<value type="QByteArray">{350f6538-4791-42f9-b43d-6ea1a7b22b7b}</value>
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="qlonglong">0</value>
</data>
<data>
<variable>ProjectExplorer.Project.EditorSettings</variable>
<valuemap type="QVariantMap">
<value type="bool" key="EditorConfiguration.AutoDetect">true</value>
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
<value type="QString" key="language">Cpp</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
</valuemap>
</valuemap>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
<value type="QString" key="language">QmlJS</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
</valuemap>
</valuemap>
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
<value type="int" key="EditorConfiguration.IndentSize">4</value>
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
<value type="int" key="EditorConfiguration.LineEndingBehavior">0</value>
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">2</value>
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
<value type="int" key="EditorConfiguration.TabSize">8</value>
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap">
<value type="int" key="RcSync">0</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<value type="QString" key="DeviceType">Desktop</value>
<value type="bool" key="HasPerBcDcs">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 6.10.1 MinGW 64-bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 6.10.1 MinGW 64-bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt6.6101.win64_mingw_kit</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:\syncMePlease\projects.now\material_dummy\build\Desktop_Qt_6_10_1_MinGW_64_bit-Debug</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">C:/syncMePlease/projects.now/material_dummy/build/Desktop_Qt_6_10_1_MinGW_64_bit-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph &quot;dwarf,4096&quot; -F 250</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">%{RunConfig:Executable:Path}</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph &quot;dwarf,4096&quot; -F 250</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">%{RunConfig:Executable:Path}</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.TargetCount</variable>
<value type="qlonglong">1</value>
</data>
<data>
<variable>Version</variable>
<value type="int">22</value>
</data>
</qtcreator>

305
doc/material_dummy/main.cpp Normal file
View File

@@ -0,0 +1,305 @@
#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QLineEdit>
#include <QSlider>
#include <QCheckBox>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QProxyStyle>
#include <QPainter>
#include <QStyleOptionSlider>
#include <QGraphicsDropShadowEffect>
#include "mainwindow.h"
// Fluent Design Demo Widget
class FluentWidgetDemo : public QWidget {
public:
FluentWidgetDemo() {
setWindowTitle("Fluent Design System - Windows 11");
resize(600, 500);
// Acrylic-like background
setStyleSheet(R"(
QWidget {
background-color: #F3F3F3;
font-family: 'Segoe UI Variable', 'Segoe UI', sans-serif;
}
)");
auto* mainLayout = new QVBoxLayout(this);
mainLayout->setSpacing(20);
mainLayout->setContentsMargins(32, 32, 32, 32);
// Title
auto* title = new QLabel("Fluent Design System");
title->setStyleSheet(R"(
font-size: 28px;
font-weight: 600;
color: #201F1E;
margin-bottom: 8px;
)");
mainLayout->addWidget(title);
auto* subtitle = new QLabel("Windows 11 Style Components");
subtitle->setStyleSheet("font-size: 14px; color: #605E5C;");
mainLayout->addWidget(subtitle);
// Text Input
auto* inputLabel = new QLabel("Text Input");
inputLabel->setStyleSheet("font-size: 12px; color: #323130; font-weight: 600;");
mainLayout->addWidget(inputLabel);
auto* input = new QLineEdit();
input->setPlaceholderText("Enter text here...");
applyFluentInput(input);
mainLayout->addWidget(input);
// Slider Section
auto* sliderLabel = new QLabel("Sliders");
sliderLabel->setStyleSheet("font-size: 12px; color: #323130; font-weight: 600; margin-top: 8px;");
mainLayout->addWidget(sliderLabel);
auto* valueLabel = new QLabel("Volume: 50");
valueLabel->setStyleSheet("font-size: 14px; color: #605E5C;");
mainLayout->addWidget(valueLabel);
auto* hSlider = new QSlider(Qt::Horizontal);
hSlider->setRange(0, 100);
hSlider->setValue(50);
hSlider->setStyle(new FluentSliderStyle());
hSlider->setMinimumHeight(32); // Genug Platz für Handle
mainLayout->addWidget(hSlider);
connect(hSlider, &QSlider::valueChanged, [valueLabel](int value) {
valueLabel->setText(QString("Volume: %1").arg(value));
});
// Checkbox
auto* checkLabel = new QLabel("Checkbox");
checkLabel->setStyleSheet("font-size: 12px; color: #323130; font-weight: 600; margin-top: 8px;");
mainLayout->addWidget(checkLabel);
auto* checkbox = new QCheckBox("Enable feature");
applyFluentCheckbox(checkbox);
mainLayout->addWidget(checkbox);
// Buttons Section
auto* btnLabel = new QLabel("Buttons");
btnLabel->setStyleSheet("font-size: 12px; color: #323130; font-weight: 600; margin-top: 8px;");
mainLayout->addWidget(btnLabel);
auto* btnLayout = new QHBoxLayout();
btnLayout->setSpacing(12);
auto* primaryBtn = new QPushButton("Primary");
applyFluentButton(primaryBtn, ButtonType::Primary);
btnLayout->addWidget(primaryBtn);
auto* secondaryBtn = new QPushButton("Secondary");
applyFluentButton(secondaryBtn, ButtonType::Secondary);
btnLayout->addWidget(secondaryBtn);
auto* subtleBtn = new QPushButton("Subtle");
applyFluentButton(subtleBtn, ButtonType::Subtle);
btnLayout->addWidget(subtleBtn);
btnLayout->addStretch();
mainLayout->addLayout(btnLayout);
// Vertical Sliders
auto* vLabel = new QLabel("Equalizer");
vLabel->setStyleSheet("font-size: 12px; color: #323130; font-weight: 600; margin-top: 8px;");
mainLayout->addWidget(vLabel);
auto* vLayout = new QHBoxLayout();
vLayout->setSpacing(24);
for (int i = 0; i < 5; ++i) {
auto* vSlider = new QSlider(Qt::Vertical);
vSlider->setRange(0, 100);
vSlider->setValue(20 + i * 15);
vSlider->setStyle(new FluentSliderStyle());
vSlider->setMinimumHeight(120);
vSlider->setMinimumWidth(32); // Genug Platz für Handle
vLayout->addWidget(vSlider);
}
vLayout->addStretch();
mainLayout->addLayout(vLayout);
mainLayout->addStretch();
}
private:
enum class ButtonType {
Primary,
Secondary,
Subtle
};
void applyFluentButton(QPushButton* btn, ButtonType type) {
QString baseStyle = R"(
QPushButton {
background-color: %1;
color: %2;
border: %3;
border-radius: 4px;
padding: 5px 12px;
font-size: 14px;
min-height: 32px;
}
QPushButton:hover {
background-color: %4;
border: %5;
}
QPushButton:pressed {
background-color: %6;
border: %7;
}
QPushButton:disabled {
background-color: #F3F2F1;
color: #A19F9D;
border: 1px solid #EDEBE9;
}
)";
switch (type) {
case ButtonType::Primary:
btn->setStyleSheet(baseStyle
.arg("#0078D4") // bg
.arg("white") // text
.arg("none") // border
.arg("#106EBE") // hover bg
.arg("none") // hover border
.arg("#005A9E") // pressed bg
.arg("none") // pressed border
);
break;
case ButtonType::Secondary:
btn->setStyleSheet(baseStyle
.arg("white") // bg
.arg("#201F1E") // text
.arg("1px solid #8A8886") // border
.arg("#F3F2F1") // hover bg
.arg("1px solid #323130") // hover border
.arg("#EDEBE9") // pressed bg
.arg("1px solid #201F1E") // pressed border
);
break;
case ButtonType::Subtle:
btn->setStyleSheet(baseStyle
.arg("transparent") // bg
.arg("#201F1E") // text
.arg("none") // border
.arg("#F3F2F1") // hover bg
.arg("none") // hover border
.arg("#EDEBE9") // pressed bg
.arg("none") // pressed border
);
break;
}
// Subtle shadow for elevation
if (type == ButtonType::Primary) {
auto* shadow = new QGraphicsDropShadowEffect();
shadow->setBlurRadius(4);
shadow->setColor(QColor(0, 0, 0, 40));
shadow->setOffset(0, 1);
btn->setGraphicsEffect(shadow);
}
}
void applyFluentInput(QLineEdit* input) {
input->setStyleSheet(R"(
QLineEdit {
border: 1px solid #8A8886;
border-radius: 4px;
padding: 6px 10px;
background-color: white;
font-size: 14px;
color: #201F1E;
min-height: 32px;
}
QLineEdit:hover {
border: 1px solid #323130;
}
QLineEdit:focus {
border: 2px solid #0078D4;
padding: 5px 9px;
}
QLineEdit:disabled {
background-color: #F3F2F1;
border: 1px solid #EDEBE9;
color: #A19F9D;
}
)");
}
void applyFluentCheckbox(QCheckBox* checkbox) {
checkbox->setStyleSheet(R"(
QCheckBox {
spacing: 8px;
font-size: 14px;
color: #201F1E;
}
QCheckBox::indicator {
width: 20px;
height: 20px;
border: 1px solid #8A8886;
border-radius: 4px;
background-color: white;
}
QCheckBox::indicator:hover {
border: 1px solid #323130;
background-color: #F3F2F1;
}
QCheckBox::indicator:checked {
background-color: #0078D4;
border: 1px solid #0078D4;
}
QCheckBox::indicator:checked:hover {
background-color: #106EBE;
border: 1px solid #106EBE;
}
QCheckBox::indicator:disabled {
background-color: #F3F2F1;
border: 1px solid #C8C6C4;
}
)");
}
};
//#include "main.moc" // Wichtig für Q_OBJECT in .cpp Datei
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// Segoe UI is default on Windows
#ifdef Q_OS_WIN
QFont font("Segoe UI Variable", 10);
#else
QFont font("Segoe UI", 10);
#endif
app.setFont(font);
TableViewDemo demo;
demo.show();
FluentWidgetDemo fdemo;
fdemo.show();
return app.exec();
}

View File

@@ -0,0 +1,2 @@

View File

@@ -0,0 +1,148 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QApplication>
#include <QWidget>
#include <QTableView>
#include <QStandardItemModel>
#include <QVBoxLayout>
#include <QHeaderView>
#include <QSlider>
#include <QPainter>
#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QLineEdit>
#include <QSlider>
#include <QCheckBox>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QProxyStyle>
#include <QPainter>
#include <QStyleOptionSlider>
#include <QGraphicsDropShadowEffect>
#include "sliderdelegate.h"
class TableViewDemo : public QWidget
{
public:
TableViewDemo()
{
setWindowTitle("QTableView mit QSlider Editor");
resize(700, 400);
auto* layout = new QVBoxLayout(this);
// Model erstellen (3 Spalten, 10 Zeilen)
auto* model = new QStandardItemModel(10, 2, this);
// Header setzen
model->setHorizontalHeaderLabels({"Name", "Wert"});
// Daten einfügen
for (int row = 0; row < 10; ++row) {
auto* nameItem = new QStandardItem(QString("Eintrag %1").arg(row + 1));
auto* valueItem = new QStandardItem();
// Wert-Item editierbar machen
valueItem->setData(row * 10, Qt::EditRole); // Startwert 0-90
valueItem->setEditable(true);
// Andere nicht editierbar
nameItem->setEditable(false);
model->setItem(row, 0, nameItem);
model->setItem(row, 1, valueItem);
}
// TableView erstellen
auto* tableView = new QTableView();
tableView->setModel(model);
// === SLIDER DELEGATE für Spalte 2 ===
//auto* sliderDelegate = new SliderDelegate(this);
//tableView->setItemDelegateForColumn(1, sliderDelegate);
tableView->setAlternatingRowColors(false);
// === LINIEN ENTFERNEN ===
tableView->setShowGrid(false);
// Header Style
tableView->horizontalHeader()->setStyleSheet(R"(
QHeaderView::section {
background-color: #F5F5F5;
padding: 10px;
border: none;
font-weight: bold;
color: #333;
}
)");
// Vertikaler Header ausblenden
tableView->verticalHeader()->setVisible(false);
// Alternating Row Colors
//tableView->setAlternatingRowColors(true);
// Style für TableView
tableView->setStyleSheet(R"(
QTableView
{
background-color: white;
border: none;
selection-background-color: #E3F2FD;
selection-color: black;
}
QTableView::item
{
padding: 10px;
border: none;
}
QTableView::item:selected {
background-color: #E3F2FD;
border: 1px solid #0078D4; /* Rahmen um JEDE Zelle */
}
}
)");
// Spaltenbreite
tableView->setColumnWidth(0, 50);
tableView->setColumnWidth(1, 150);
tableView->horizontalHeader()->setStretchLastSection(true);
// Row Height für bessere Slider-Darstellung
tableView->verticalHeader()->setDefaultSectionSize(40);
// Selection
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
//tableView->setSelectionMode(QAbstractItemView::SingleSelection);
// Edit Trigger - Klick zum Editieren
tableView->setEditTriggers(QAbstractItemView::DoubleClicked |
QAbstractItemView::SelectedClicked);
layout->addWidget(tableView);
// Signal für Änderungen
connect(model, &QStandardItemModel::dataChanged, this,
[](const QModelIndex& topLeft, const QModelIndex& bottomRight) {
if (topLeft.column() ==1) {
int row = topLeft.row();
int value = topLeft.data(Qt::DisplayRole).toInt();
qDebug() << "Zeile" << row << "wurde auf" << value << "gesetzt";
}
});
}
};
#endif // MAINWINDOW_H

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>18</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,25 @@
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h \
sliderdelegate.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

View File

@@ -0,0 +1,355 @@
#ifndef SLIDERDELEGATE_H
#define SLIDERDELEGATE_H
#include <QStyledItemDelegate>
#include <QApplication>
#include <QWidget>
#include <QTableView>
#include <QStandardItemModel>
#include <QVBoxLayout>
#include <QHeaderView>
#include <QSlider>
#include <QPainter>
#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QLineEdit>
#include <QSlider>
#include <QCheckBox>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QProxyStyle>
#include <QPainter>
#include <QStyleOptionSlider>
#include <QGraphicsDropShadowEffect>
// Custom Delegate für QSlider in Spalte 3
// Fluent Design Slider Style
class FluentSliderStyle : public QProxyStyle
{
public:
FluentSliderStyle()
: QProxyStyle()
{}
// Wichtig: Genug Platz für Handle reservieren
int pixelMetric(PixelMetric metric, const QStyleOption* option = nullptr, const QWidget* widget = nullptr) const override
{
switch (metric)
{
case PM_SliderThickness:
return 32; // Höhe für horizontalen Slider
case PM_SliderLength:
return 20; // Handle-Größe
case PM_SliderControlThickness:
return 20;
case PM_SliderSpaceAvailable:
if (option)
{
if (const QStyleOptionSlider* sliderOpt = qstyleoption_cast<const QStyleOptionSlider*>(option)) {
if (sliderOpt->orientation == Qt::Horizontal) {
return sliderOpt->rect.width() - 20;
} else {
return sliderOpt->rect.height() - 20;
}
}
}
return QProxyStyle::pixelMetric(metric, option, widget);
default:
return QProxyStyle::pixelMetric(metric, option, widget);
}
}
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex* opt,SubControl sc, const QWidget* widget) const override
{
if (cc == CC_Slider) {
if (const QStyleOptionSlider* slider = qstyleoption_cast<const QStyleOptionSlider*>(opt)) {
QRect rect = slider->rect;
int handleSize = 20;
if (sc == SC_SliderHandle) {
// Handle Position korrekt berechnen
if (slider->orientation == Qt::Horizontal) {
int range = slider->maximum - slider->minimum;
int pos = slider->sliderPosition - slider->minimum;
int pixelRange = rect.width() - handleSize;
int pixelPos = (range != 0) ? (pos * pixelRange) / range : 0;
return QRect(rect.x() + pixelPos,
rect.center().y() - handleSize / 2,
handleSize, handleSize);
} else {
int range = slider->maximum - slider->minimum;
int pos = slider->sliderPosition - slider->minimum;
int pixelRange = rect.height() - handleSize;
int pixelPos = (range != 0) ? (pos * pixelRange) / range : 0;
return QRect(rect.center().x() - handleSize / 2,
rect.bottom() - pixelPos - handleSize,
handleSize, handleSize);
}
}
}
}
return QProxyStyle::subControlRect(cc, opt, sc, widget);
}
void drawComplexControl(ComplexControl control, const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget) const override
{
if (control == CC_Slider)
{
if (const QStyleOptionSlider* slider = qstyleoption_cast<const QStyleOptionSlider*>(option)) {
painter->setRenderHint(QPainter::Antialiasing);
// Fluent Colors
QColor accentColor(0, 120, 212); // #0078D4
QColor inactiveColor(138, 136, 134); // #8A8886
QColor bgColor(255, 255, 255); // White background
if (slider->orientation == Qt::Horizontal) {
drawHorizontalFluentSlider(painter, slider, accentColor, inactiveColor, bgColor);
} else {
drawVerticalFluentSlider(painter, slider, accentColor, inactiveColor, bgColor);
}
return;
}
}
QProxyStyle::drawComplexControl(control, option, painter, widget);
}
private:
void drawHorizontalFluentSlider(QPainter* painter, const QStyleOptionSlider* slider,
const QColor& activeColor, const QColor& inactiveColor,
const QColor& bgColor) const {
QRect groove = slider->rect;
QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, nullptr);
int grooveHeight = 4;
// Track sollte im Widget-Zentrum sein, nicht im groove-Zentrum
int grooveY = slider->rect.center().y() - grooveHeight / 2;
// Full background track
QRect fullTrack(groove.left(), grooveY, groove.width(), grooveHeight);
painter->setPen(Qt::NoPen);
painter->setBrush(inactiveColor.lighter(150));
painter->drawRoundedRect(fullTrack, grooveHeight / 2, grooveHeight / 2);
// Active track (filled portion)
int activeWidth = handle.center().x() - groove.left();
QRect activeTrack(groove.left(), grooveY, activeWidth, grooveHeight);
painter->setBrush(activeColor);
painter->drawRoundedRect(activeTrack, grooveHeight / 2, grooveHeight / 2);
// Handle (Thumb) - Fluent style is more subtle
int handleSize = 20;
QRect thumbRect(handle.center().x() - handleSize / 2,
handle.center().y() - handleSize / 2,
handleSize, handleSize);
// Hover effect - subtle glow
if (slider->state & State_MouseOver) {
painter->setBrush(QColor(activeColor.red(), activeColor.green(),
activeColor.blue(), 30));
int glowSize = 32;
QRect glow(handle.center().x() - glowSize / 2,
handle.center().y() - glowSize / 2,
glowSize, glowSize);
painter->drawEllipse(glow);
}
// Thumb
painter->setBrush(bgColor);
painter->setPen(QPen(activeColor, 2));
painter->drawEllipse(thumbRect);
// Inner circle for pressed state
if (slider->state & State_Sunken) {
int innerSize = 8;
QRect inner(handle.center().x() - innerSize / 2,
handle.center().y() - innerSize / 2,
innerSize, innerSize);
painter->setPen(Qt::NoPen);
painter->setBrush(activeColor);
painter->drawEllipse(inner);
}
}
void drawVerticalFluentSlider(QPainter* painter, const QStyleOptionSlider* slider,
const QColor& activeColor, const QColor& inactiveColor,
const QColor& bgColor) const {
QRect groove = slider->rect;
QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, nullptr);
int grooveWidth = 4;
// Track sollte im Widget-Zentrum sein
int grooveX = slider->rect.center().x() - grooveWidth / 2;
// Full background track
QRect fullTrack(grooveX, groove.top(), grooveWidth, groove.height());
painter->setPen(Qt::NoPen);
painter->setBrush(inactiveColor.lighter(150));
painter->drawRoundedRect(fullTrack, grooveWidth / 2, grooveWidth / 2);
// Active track
int activeHeight = groove.bottom() - handle.center().y();
QRect activeTrack(grooveX, handle.center().y(), grooveWidth, activeHeight);
painter->setBrush(activeColor);
painter->drawRoundedRect(activeTrack, grooveWidth / 2, grooveWidth / 2);
// Handle
int handleSize = 20;
QRect thumbRect(handle.center().x() - handleSize / 2,
handle.center().y() - handleSize / 2,
handleSize, handleSize);
if (slider->state & State_MouseOver) {
painter->setBrush(QColor(activeColor.red(), activeColor.green(),
activeColor.blue(), 30));
int glowSize = 32;
QRect glow(handle.center().x() - glowSize / 2,
handle.center().y() - glowSize / 2,
glowSize, glowSize);
painter->drawEllipse(glow);
}
painter->setBrush(bgColor);
painter->setPen(QPen(activeColor, 2));
painter->drawEllipse(thumbRect);
if (slider->state & State_Sunken) {
int innerSize = 8;
QRect inner(handle.center().x() - innerSize / 2,
handle.center().y() - innerSize / 2,
innerSize, innerSize);
painter->setPen(Qt::NoPen);
painter->setBrush(activeColor);
painter->drawEllipse(inner);
}
}
};
class SliderDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
SliderDelegate(QObject* parent = nullptr)
: QStyledItemDelegate(parent)
{}
// Editor erstellen (QSlider)
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,const QModelIndex& index) const override
{
Q_UNUSED(option)
Q_UNUSED(index)
auto* slider = new QSlider(Qt::Horizontal, parent);
slider->setRange(0, 100);
slider->setSingleStep(1);
slider->setPageStep(10);
slider->setStyle(new FluentSliderStyle());
// Signal für sofortige Updates
connect(slider, &QSlider::valueChanged, this, [this, slider]() {
// Commit data sofort bei Änderung
emit const_cast<SliderDelegate*>(this)->commitData(slider);
});
return slider;
}
// Editor mit aktuellem Wert füllen
void setEditorData(QWidget* editor, const QModelIndex& index) const override {
int value = index.model()->data(index, Qt::EditRole).toInt();
auto* slider = static_cast<QSlider*>(editor);
slider->setValue(value);
}
// Wert vom Editor ins Model schreiben
void setModelData(QWidget* editor, QAbstractItemModel* model,
const QModelIndex& index) const override {
auto* slider = static_cast<QSlider*>(editor);
int value = slider->value();
model->setData(index, value, Qt::EditRole);
}
// Editor-Geometrie (wichtig für korrekte Positionierung)
void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option,
const QModelIndex& index) const override {
Q_UNUSED(index)
/*
QRect barRect = option.rect.adjusted(option.rect.width() - 55,
option.rect.height() / 2 - 2,
-8,
-option.rect.height() / 2 + 2);
*/
QRect sliderRect = option.rect.adjusted(
option.rect.width() - 115, // Von rechts: 115px (Breite der Progress Bar)
0, // Oben: kein Offset
-8, // Rechts: 8px Padding
0 // Unten: kein Offset
);
editor->setGeometry(sliderRect); // Slider nur über Progress Bar
//editor->setGeometry(option.rect);
}
// Anzeige wenn NICHT editiert wird
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override
{
if (index.column() == 1)
{ // Nur für Wert-Spalte
// Wert holen
int value = index.model()->data(index, Qt::DisplayRole).toInt();
// Hintergrund
if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.highlight());
} else if (index.row() % 2 == 1) {
painter->fillRect(option.rect, QColor(0xFAFAFA));
} else {
painter->fillRect(option.rect, Qt::white);
}
// Text und kleiner Slider-Indikator zeichnen
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
QRect textRect = option.rect.adjusted(8, 0, -120, 0);
QRect barRect = option.rect.adjusted(option.rect.width() - 115,
option.rect.height() / 2 - 2,
-8,
-option.rect.height() / 2 + 2);
// Text
painter->setPen(option.state & QStyle::State_Selected ?
option.palette.highlightedText().color() : Qt::black);
painter->drawText(textRect, Qt::AlignVCenter | Qt::AlignLeft,
QString::number(value));
// Mini Progress Bar
painter->setPen(Qt::NoPen);
painter->setBrush(QColor(0xE0E0E0));
painter->drawRoundedRect(barRect, 2, 2);
QRect fillRect = barRect;
fillRect.setWidth(barRect.width() * value / 100);
painter->setBrush(QColor(0x0078D4));
painter->drawRoundedRect(fillRect, 2, 2);
painter->restore();
} else {
// Standard-Zeichnung für andere Spalten
QStyledItemDelegate::paint(painter, option, index);
}
}
};
#endif // SLIDERDELEGATE_H