Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Chaning border color from QTextTable with QColor-Dialog

Chaning border color from QTextTable with QColor-Dialog

Scheduled Pinned Locked Moved Solved General and Desktop
qcolordialogqtexttableborder
3 Posts 2 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi. How can i Change the Color of QTextTable border with a Color Dialog? I know that i can Change it with QBrush and QTextTableFormat but how can i do this with a Color Dialog?

    1 Reply Last reply
    0
    • X Offline
      X Offline
      XavierLL
      wrote on last edited by
      #2

      Hi,

      If you want to pick a color from a Color Dialog, just use the static method getColor in <QColorDialog>

      QColor color = QColorDialog::getColor();
      

      Then you can use this color to change your QTextTAbleFormat.

      see you!

      1 Reply Last reply
      0
      • X Offline
        X Offline
        XavierLL
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved