Forum
Sign Up
× DataGrid for Qt.C++

Change the background color of a cell

11 years 10 months ago #1 by
Hi,
i want to change the background color of a cell if it's readonly. I make a special editor and overwrite the paintEvent. In the method i set the following:
GridEditorStyleOption newOption(option);
	QRect rect = option.rect;
	rect.adjust(4, 4, -4, -4);
	newOption.rect = rect;
	newOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
	if(isReadOnly())
	{
		newOption.backgroundBrush = QBrush(Qt::lightGray, Qt::Dense6Pattern);
		painter.setBackground(newOption.backgroundBrush);
	}
	Qtitan::GridStringEditor::paintEvent(painter, newOption);

But the background for readonly cells will not changed.

What's wrong?

Thanks

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

  • 's Avatar Topic Author
11 years 10 months ago #2 by Developer Machines
Grid is responsible for drawing the background, not the editor of the cell.
But if you want to render it in the editor, you can do it directly in the section where you assign a background color.
if(isReadOnly())
{
	painter.fillRect(rect, QBrush(Qt::lightGray, Qt::Dense6Pattern));
}
The following user(s) said Thank You:

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