Voici un exemple re réponse:
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QMainWindow>
#include <QPainter>
#include <QLine>
#include <QPen>
#include <QGroupBox>
#include <QGridLayout>
#include <QScrollArea>
#include <QPaintEvent>
#include <qDebug>
#include <QPushButton>
#include <QApplication>
#include <QLabel>
class Widget : public QMainWindow
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
private:
};
#endif // WIDGET_H
widget.cpp
#include "widget.h"
#include "zonescroll.h"
Widget::Widget(QWidget *parent)
: QMainWindow(parent)
{
ZoneScroll *zone = new ZoneScroll;
QScrollArea *scroll = new QScrollArea ;
scroll->setFixedHeight(800);
scroll->setFixedWidth(1000);
scroll->setWidget(zone);
QWidget *central = scroll;
QGroupBox *box = new QGroupBox("Rolland",central);
box->setFixedWidth(600);
box->setFixedHeight(100);
QGridLayout *layout = new QGridLayout();
layout->addWidget(box,2,3);
central->setLayout(layout);
this->setCentralWidget(central);
zone->setGeometry(QRect(110, 80, 1200, 300));
QPushButton *Quitter = new QPushButton("Quitter",scroll);
Quitter->setGeometry(1000,20,100,30);
QObject::connect(Quitter, SIGNAL(clicked()), qApp, SLOT(quit()));
}
Widget::~Widget()
{
}
zonescroll.h
#ifndef ZONESCROLL_H
#define ZONESCROLL_H
#include <QtGui>
#include <QWidget>
#include <QGroupBox>
#include <QGridLayout>
class ZoneScroll : public QWidget
{
Q_OBJECT
public:
ZoneScroll(QWidget *parent = 0);
void paintEvent(QPaintEvent *event);
};
#endif // ZONESCROLL_H
zonescroll.cpp
#include "zonescroll.h"
ZoneScroll::ZoneScroll(QWidget *parent) : QWidget(parent)
{
}
void ZoneScroll::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QLine *line = new QLine();
QPen *couleur = new QPen();
couleur->setColor(Qt::blue);
couleur->setWidth(3);
line->setLine(50,50,300,80);
painter.setPen(*couleur);
painter.drawLine(*line);
}
main.cpp
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}