Here's the solution:

There's a very neat method for finding this, inspired by the no-computers way of solving another related puzzle. Namely,
put labels $A, B, C, D, E, F, G$ along the top for each column, and then label the rows by certain subsets of the set $\{A, B, C, D, E, F, G\}$.
More specifically, given the constraints of this problem:
7 rows, so 7 different subsets;
21 painted cells, so each subset should be of size 3;
no rectangles, so no pair of subsets has two elements in common.
How can we achieve this?
Without loss of generality, say the first subset is $\{A,B,C\}$. The six remaining subsets are found by associating each one of $A,B,C$ together with one of the three ways of dividing $\{D,E,F,G\}$ into pairs.
The way I used (unique up to swapping of rows and columns) is
ABC, ADE, AFG, BDF, BEG, CDG, CEF.
That gives the following grid:
A B C D E F G
ABC - - -
ADE - - -
AFG - - -
BDF - - -
BEG - - -
CDG - - -
CEF - - -
which is what I put at the top in nicer formatting.