Forum
Sign Up
× DataGrid for Qt.C++

Make Grid header editable

6 years 2 months ago #1 by Jennifer
Hi,

Could you please let me know the way to make grid headers editable? I have attached an image file to demonstrate the expected behavior. Please find same.
Attachments:

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago #2 by Jennifer
Replied by Jennifer on topic Make Grid header editable
Hi,

Any updates?

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago - 6 years 1 month ago #3 by Developer Machines
For this purpose you need implement Qtitan::GridTableColumnEditor and assign it to Qtitan::GridTableColumn. See example below:

main.cpp
#include <QApplication>
#include "window.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Window w;
    w.show();
    return a.exec();
}

window.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtitanGrid.h>

class Window : public QMainWindow
{
    Q_OBJECT
public:
    Window();
 private:
    Qtitan::Grid* m_grid;
};

class MyColumnEditor : public Qtitan::GridTableColumnEditor
{
    Q_OBJECT
public:
    MyColumnEditor();
    virtual QWidget* createEditorWidget(Qtitan::GridColumnBase* column);
private Q_SLOTS:
    void editChanged(const QString &);
private:
};
#endif // MAINWINDOW_H

window.cpp
#include <QStandardItemModel>

#include "window.h"

Window::Window()
: QMainWindow()
{
    setWindowTitle(tr("QtitanDataGrid Demo"));
    setGeometry(200, 250, 1200, 800);

    m_grid = new Qtitan::Grid();
    m_grid->setViewType(Qtitan::Grid::TableView);
    Qtitan::GridTableView* view = m_grid->view<Qtitan::GridTableView>();
    view->options().setColumnHeight(35);

    QStandardItemModel* model =  new QStandardItemModel(4, 4);
    for (int row = 0; row < 4; ++row)
    {
        for (int column = 0; column < 4; ++column)
        {
            QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column));
            model->setItem(row, column, item);
        }
    }
    view->setModel(model);

    MyColumnEditor* editor = new MyColumnEditor();
    Qtitan::GridTableColumn* column = (Qtitan::GridTableColumn *)view->getColumn(0);
    column->setColumnEditor(editor);

    setCentralWidget(m_grid);
}

/* MyColumnEditor */
MyColumnEditor::MyColumnEditor()
    : Qtitan::GridTableColumnEditor()
{
}

QWidget* MyColumnEditor::createEditorWidget(Qtitan::GridColumnBase* column)
{
    Q_UNUSED(column);
    QLineEdit* edit = new QLineEdit();
    connect(edit, SIGNAL(textEdited(const QString &)), this, SLOT(editChanged(const QString &)));
    return edit;
}

void MyColumnEditor::editChanged(const QString &)
{
}


Attachments:
Last edit: 6 years 1 month ago by Developer Machines.

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago - 6 years 1 month ago #4 by Jennifer
Replied by Jennifer on topic Make Grid header editable
Thanks for the reply,
I think you did not understood my question.
I want to make grid header editable on double click of grid header column and set edited value on header column after finishing edit operation.
Please let us know how to do that?
Last edit: 6 years 1 month ago by Jennifer.

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago #5 by Developer Machines
Unfortunately, at the moment there is no such feature (ability to edit header text).

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago - 6 years 1 month ago #6 by Jennifer
Replied by Jennifer on topic Make Grid header editable
Could you please let us know whether this feature is going to available in later releases.
Last edit: 6 years 1 month ago by Jennifer.

Please Log in or Create an account to join the conversation.

More
  • Not Allowed: to create new topic.
  • Not Allowed: to reply.
  • Not Allowed: to edit your message.
Moderators: Developer Machines
Time to create page: 0.145 seconds

Developer Newsletter

Join our Developer Machines newsletter to get informed on all the latest releases of the commercial components for Qt.C++, Delphi FireMonkey, updates and general knowledges.

Quick Support

Should you need any additional information about our products or licensing, please contact us at the following email addresses:

  • This email address is being protected from spambots. You need JavaScript enabled to view it.

  • This email address is being protected from spambots. You need JavaScript enabled to view it.

Get in Touch

If you would like to purchase our products or services, but don’t know how to do it the right way, please feel free to contact us:

  • This email address is being protected from spambots. You need JavaScript enabled to view it.( any questions related to our products or services )
  • This email address is being protected from spambots. You need JavaScript enabled to view it.( questions related to licensing )