Forum
Sign Up
× DataGrid for Qt.C++

Possibility to show all text columns default in alignment left?

3 years 10 months ago #1 by Michael
Hi Devmachines,

is there a possibility to show all text columns default in text alignment left and not in right?
I found in the GridColumnBase Constructor the AlignRight statement for all columns in default.
I would not change this because then also numeric columns are alignet right by default.

Thanks for feedback.
Michael

GridColumnBase::GridColumnBase(GridViewBase* view, const QString& caption)
: QObject(view->grid()), m_visible(true), m_fixedPosition(Qtitan::AtNone), m_view(view),
m_caption(caption),
m_captionVisible(true),
m_textAlignment(Qt::AlignVCenter | Qt::AlignRight),
m_iconAlignment(Qt::AlignVCenter | Qt::AlignLeft),
m_textElideMode(Qt::ElideRight), m_textOrientation(Qt::Horizontal),
m_decorationColor(Qt::transparent), m_columnEditor(Q_NULL),
m_isHidingEnabled(true), m_isMovingEnabled(true), m_isHorSizingEnabled(true), m_autoWidth(true),
m_minWidth(QtnGridMinTableColumnWidth), m_maxWidth(QtnGridMaxTableColumnWidth),
m_menuButtonVisible(false)
{
}

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

More
3 years 10 months ago - 3 years 10 months ago #2 by Developer Machines
Unfortunately, this setting is customizable individually for each column. But it’s easy enough to write a function that will change this setting for all columns at a time.
static void setViewAlign(GridViewBase* view, Qt::Alignment alignment)
{
    for (int i = 0; i < view->getColumnCount(); ++i)
    {
        view->getColumn(i)->setTextAlignment(alignment);
    }
}

setViewAlign(m_grid->view<Qtitan::GridBandedTableView>(), Qt::AlignLeft);

Also, this setting can be changed by the end-user, if he call the popup menu at the column.
Last edit: 3 years 10 months ago by Developer Machines.

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

More
3 years 10 months ago #3 by Michael
Thanks for this information.
In this case I have to mark each field wheter the value of the column is a text or not.
Is there a possibility to get this information automatically like by the grouping decision if I can use the summary function. Or in the footer line. There it is only possible to calculate a summ if the field value is not a text.

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

More
3 years 10 months ago - 3 years 10 months ago #4 by Developer Machines
If I understand you correctly, you need to get the type of editor that is used for editing in the column.
if (static_cast<GridColumn *>(view->getColumn(i))->editorType() == GridEditor::String)
          view->getColumn(i)->setTextAlignment(alignment);
Last edit: 3 years 10 months ago by Developer Machines.

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

More
3 years 10 months ago #5 by Michael
Yes your understanding was correct.

I tried your suggestion.

But I always gives back the Value GridEditor::Auto
And this for numeric fields and string fields.

I tried to use the value of supportedSummaryTypes also. But this ist always 0.
for (int i = 0; i < view->getColumnCount(); ++i) {

        GridTableColumn *currentColumn = static_cast<GridTableColumn *>(view->getColumn(i));

        //        if (currentColumn->editorType() == GridEditor::String) {
        if (currentColumn->dataBinding()->supportedSummaryTypes() == GridSummary::Count) {
            currentColumn->setTextAlignment(Qt::AlignLeft);

In my understanding the editorType GridEditor::String has to be set manually first. If I don't set this type then the GridEditor value is always GridEditor::Auto

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

More
3 years 10 months ago #6 by Developer Machines
In case of Auto editor type use the cast to the string editor class like this:
if (qobject_cast<GridStringEditorRepository *>(static_cast<GridColumn *>(view->getColumn(i))->editorRepository()) != Q_NULL)
          view->getColumn(i)->setTextAlignment(alignment);

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.140 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 )