I'm attempting to create a widget that consists of of a single horizontal black line. This widget will be placed in a QGridLayout such that it takes up the entire row, thus acting as a separator. As the widget upon which the layout is installed is resized, I'd like the line to change it's size to keep up. I've checked out a number of options, including QLine, QGraphicsView and QImage, but I can't seem to get the line drawn, never mind get it to resize.
I'm implementing this in it's own class so I can reuse it as and when it's needed. Can anyone please help me with this?
#include "startMenuSectionFooter.h"
#include <QtGui>
StartMenuSectionFooter::StartMenuSectionFooter( QWidget *parent )
: QWidget( parent )
{
layout = new QHBoxLayout( this );
}
void StartMenuSectionFooter::paintEvent( QPainEvent *e )
{
QPointF p1 = QPointF( parentWidget()->height(), 0 );
QPointF p2 = QPointF( parentWidget()->height(), parentWidget()->width() );
QPainter painter( this );
painter.setRenderHint( QPainter::Antialiasing, true );
painter.setPen( QPen( Qt::black, 10 ) );
painter.drawLine( p1, p2 );
}
In this case, parent
is the parentQWidget
upon which the QGridLayout
mentioned earlier is installed.
#ifndef START_MENU_SECTION_FOOTER_H
#define START_MENU_SECTION_FOOTER_H
#include <QWidget>
class QHBoxLayout;
class QPainEvent;
class StartMenuSectionFooter : public QWidget
{
Q_OBJECT
QBHoxLayout *layout;
void paintEvent( QPainEvent *e );
public:
StartMenuSectionFooter( QWidget *parent = NULL );
};
#endif