1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include <QtGui>
class myWindows : public QWidget
{
Q_OBJECT
public :
myWindows()
:QWidget(0,Qt::FramelessWindowHint)
{
resize(800,600);
m_gL = new QVBoxLayout;
m_gL->setMargin(2);
m_gL->setSpacing(2);
QWidget * bar_Titre = new QWidget;
//creation de la bar de titre
bar_Titre->setFixedHeight(20);
{
QHBoxLayout * l = new QHBoxLayout;
l->setMargin(0);
l->setSpacing(2);
l->addWidget(new QLabel ("ma bar de titre"),Qt::AlignLeft);
l->addSpacing(100);
QPushButton * but =new QPushButton("+");
but->setFixedSize(18,18);
connect(but,SIGNAL(clicked()),this,SLOT(maximiser()));
l->addWidget(but,Qt::AlignRight);
but =new QPushButton("x");
but->setFixedSize(18,18);
l->addWidget(but,Qt::AlignRight);
connect(but,SIGNAL(clicked()),this,SLOT(close()));
bar_Titre->setLayout(l);
QString style ="QWidget {"
" background: qlineargradient(x1: 0, y1: 1, x2: 0, y2: 0,"
" stop: 0 #00FF00, stop: 1 #FFFFFF);"
"}";
bar_Titre->setStyleSheet(style);
}
m_gL->addWidget(bar_Titre);
setLayout(m_gL);
}
void addWidget(QWidget *w)
{
m_gL->addWidget(w);
}
protected :
//gestion de la souris pour bouger la fenetre
void mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
dragPosition = event->globalPos() - frameGeometry().topLeft();
event->accept();
}
}
void mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton) {
move(event->globalPos() - dragPosition);
event->accept();
}
}
private slots :
//slot pour minimiser/maximiser
void maximiser()
{
if (isMaximized ())
showNormal();
else
showMaximized();
}
private :
QVBoxLayout * m_gL;
QPoint dragPosition;
};
#include "main.moc"
int main(int argc, char *argv[])
{
QApplication app(argc,argv);
myWindows w;
QListView * lw = new QListView;
{
QStringList list;
list<<"essai 1"<<"esssai 2"<<"blablabla"<<"aze"<<"azzddz";
lw->setModel(new QStringListModel(list));
}
QMainWindow * mainWindow = new QMainWindow;
{
QToolBar * toolBar = new QToolBar;
toolBar->addAction("aze");
toolBar->addAction("azer");
mainWindow->addToolBar(toolBar);
mainWindow->setCentralWidget(lw);
}
w.addWidget(mainWindow);
w.show();
return app.exec();
} |
Partager