Hi Henrik,
as you requested by chat this is a more deep example.
#ifndef MAINWIDGET_H
#define MAINWIDGET_H
#include <QWidget>
class QResizeEvent;
class QTextTable;
class MainWidget : public QWidget
{
Q_OBJECT
public:
MainWidget(QWidget *parent = 0);
~MainWidget();
protected:
void resizeEvent(QResizeEvent *event) override;
public slots:
void contextMenuRequested(const QPoint& pos);
void showColorPicker();
private:
QTextTable *_table;
};
#endif // MAINWIDGET_H
#include "MainWidget.h"
#include <QTextEdit>
#include <QTextCursor>
#include <QTextTable>
#include <QMenu>
#include <QAction>
#include <QColorDialog>
#include <QDebug>
MainWidget::MainWidget(QWidget *parent)
: QWidget(parent)
{
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, &QWidget::customContextMenuRequested,this, &MainWidget::contextMenuRequested);
}
MainWidget::~MainWidget()
{
}
void MainWidget::contextMenuRequested(const QPoint& pos)
{
qDebug() << "Menu Requested";
QMenu *contextMenu = new QMenu(this);
QAction *action = contextMenu->addAction("Color");
contextMenu->popup(mapToGlobal(pos));
connect(action, &QAction::triggered, this, &MainWidget::showColorPicker);
}
void MainWidget::resizeEvent(QResizeEvent *event)
{
QTextEdit *te = new QTextEdit(this);
QTextCursor cursor = te->textCursor();
QTextTableFormat tf;
tf.setBorderBrush(Qt::red);
_table = cursor.insertTable(5, 5, tf);
}
void MainWidget::showColorPicker()
{
QColor color = QColorDialog::getColor();
QTextTableFormat tf = _table->format();
tf.setBorderBrush(color);
_table->setFormat(tf);
}
Maybe you could change the QTextDocument style, to change all the tables in the document, this is somenthing I don't know.
Hope this helps!