-1

I am writing a little program in C++ with Qt. I have a QGridLayout with 3*3 QWidget. In each QWidget, I have a QVBoxLayout. Within that QVBoxLayout I need to put a certain number of black and white rectangles.

For now, I use QWidgets for these rectangle and I apply a background-color to get the white and the black ones.

I saw in the documentation something about a Rectangle class that is linked with QtQuick and I don't really want to go into that.

Thanks for your answers,

Nono
  • 33
  • 7

2 Answers2

1

I wouldn't bother with the layout and widgets unless you actually need interactive objects for each square. Just overload the paintEvent member of the widget you are using that contains the grid layout and use the QPainter object and call fillRect.

cppguy
  • 3,611
  • 2
  • 21
  • 36
  • Thanks for your answer. I have just tried to use QPainter. It seems to be a good idea but here, in order to display rectangle in a column, I would need to compute the exact position in pixel ?Is there a way to avoid doing that ? – Nono May 21 '14 at 20:01
  • No, there's no way to avoid that but the math is trivial – cppguy May 21 '14 at 21:53
0

To get an outline around a widget, use a QFrame. Also QLabel subclasses QFrame. There are a lot of examples of using QFrame in the documentation.

Hope that helps.

phyatt
  • 18,472
  • 5
  • 61
  • 80