Signals et slots dans Qt

cs_fantaorange Messages postés 4 Date d'inscription vendredi 24 octobre 2008 Statut Membre Dernière intervention 27 février 2009 - 27 févr. 2009 à 18:42
SebLinck Messages postés 212 Date d'inscription mardi 17 mai 2005 Statut Membre Dernière intervention 23 juin 2011 - 2 mars 2009 à 09:22
Bonjour,

Je n'arrive pas à comprendre comment faire pour modifier les coordonnées automatiquement de la position du deuxieme point de:
QLinearGradient linearGrad(QPointF(0, 0), QPointF(largeur, hauteur));
lorsque la fenetre change de taille... Désolé chui un peu débutant...

Voici mon code:
main.cpp
#include <QApplication>
#include <QtGui>
#include "fenPrincipale.h"


int main(int argc, char *argv[])
{
    QApplication app(argc, argv);


    fenPrincipale fenetre;
    fenetre.show();


    return app.exec();
}

fenPrincipale.h
#ifndef HEADER_FENPRINCIPALE
#define HEADER_FENPRINCIPALE



#include <QtGui>
#include <QApplication>



class fenPrincipale : public QMainWindow
{
    Q_OBJECT



 public:
  fenPrincipale();



    public slots:
        void changerLargeur(int largeur, int hauteur);



 private:
 
};



#endif


fenPrincipale.cpp

#include "fenPrincipale.h"



fenPrincipale::fenPrincipale()
{



    //options fenetre principale
    setWindowIcon(QIcon("icone_fenPrincipale.png"));
    resize(1000, 800);



    //QMdiArea comme widget conteneur pour la zone centrale
    QMdiArea *zoneCentrale = new QMdiArea;
    setCentralWidget(zoneCentrale); //centrer le widget
    
   //fond de zonecentrale

   QLinearGradient linearGrad(QPointF(0, 0), QPointF(width(), height()));
    linearGrad.setColorAt(0, Qt::blue);
    linearGrad.setColorAt(1, Qt::white);
    zoneCentrale->setBackground(QBrush::QBrush(linearGrad));



    QObject::connect(this, SIGNAL(width(int),heigth(int)), this, SLOT(changerGradient(int,int)));



}



void fenPrincipale::changerGradient(int largeur, int hauteur)
{
    QLinearGradient linearGrad(QPointF(0, 0), QPointF(largeur, hauteur));
    linearGrad.setColorAt(0, Qt::blue);
    linearGrad.setColorAt(1, Qt::white);
    zoneCentrale->setBackground(QBrush::QBrush(linearGrad));
}

Merci beaucoup d'avance pour vos conseils











 

1 réponse

SebLinck Messages postés 212 Date d'inscription mardi 17 mai 2005 Statut Membre Dernière intervention 23 juin 2011
2 mars 2009 à 09:22
Salut,
Je crois que tu connectes 2 SIGNAL à 1 SLOT, essayes de connecer 1 SIGNAL à 1 SLOT,
Vérifies que les signaux existent bien...

Cordialement,
Sébastien.
0
Rejoignez-nous