Bonjour, j'ai suivi ce tutoriel pour créer une fenêtre personnalisée, jusqu'à en arriver aux boutons tout allait bien. Mais lorsque je suis arrivé à la partie sur les boutons le manque de description du code ne m'a pas permis de comprendre ce qu'il faisait, j'ai donc décidé de réaliser les boutons en ne faisant que m'aider du code du tutoriel. Le problème est que lorsque je connecte le signal du clic (clicked()) au slot de minimisation de la fenêtre, je reçoit l'erreur :
1 2 3 | \windowtitlebar.cpp:6: erreur : no matching function for call to 'WindowTitleBar::connect(MinimizeButton*&, const char*, WindowTitleBar* const, const char*)' QObject::connect(m_Minimize, SIGNAL(clicked()), this, SLOT(Minimized())); ^ |
Ne comprenant pas l'origine de cette erreur, je fais appel à vous.
Voilà le fichier windowtitlebar.cpp :
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 | #include "windowtitlebar.h" WindowTitleBar::WindowTitleBar(QWidget *parent) : QWidget(parent) { m_Minimize = new MinimizeButton(); QObject::connect(m_Minimize, SIGNAL(clicked()), this, SLOT(Minimized())); m_Cache = NULL; m_Title = new QLabel(this); m_Title->setStyleSheet("color: rgb(68, 68, 68); font-family: \"Segoe UI\"; font-size: 12px"); setFixedHeight(28); UpdateWindowTitle(); } WindowTitleBar::~WindowTitleBar() { } void WindowTitleBar::resizeEvent(QResizeEvent *event) { Q_UNUSED(event); delete m_Cache; m_Cache = new QPixmap(size()); m_Cache->fill(Qt::transparent); QPainter painter(m_Cache); QColor lightBlue (177, 177, 203, 255); /********** Title Frame **********/ QBrush frameBackground(QColor(0, 255, 255)); QPolygon frame; frame << QPoint(1, 1) << QPoint(width() - 1, 1) << QPoint(width() - 1, 28) << QPoint(1, 28); painter.setBrush(frameBackground); painter.setPen(Qt::NoPen); painter.drawPolygon(frame); /*************************************/ QPolygon buttons; buttons << QPoint(width() - 80, 4) << QPoint(width() - 4, 4) << QPoint(width() - 4, 32) << QPoint(width() - 88, 32) << QPoint(width() - 88, 12); painter.setPen (QPen (lightBlue)); painter.setBrush(QBrush(lightBlue)); painter.drawPolygon(buttons); m_Title->move(((width() / 2) - (m_Title->fontMetrics().boundingRect(m_Title->text()).width() / 2)), 8); } void WindowTitleBar::paintEvent(QPaintEvent *event) { Q_UNUSED(event); if(m_Cache != NULL) { QPainter painter(this); painter.drawPixmap(0, 0, *m_Cache); } } void WindowTitleBar::UpdateWindowTitle() { m_Title->setText(window()->windowTitle()); } void WindowTitleBar::Minimized() { window()->showMinimized(); } void WindowTitleBar::Maximized() { if(window()->windowState() == Qt::WindowMaximized) { window()->showNormal(); } else { window()->showMaximized(); } } void WindowTitleBar::Quit() { //app->quit(); } |
Le code du fichier windowtitlebar.h :
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 | #ifndef WINDOWTITLEBAR_H #define WINDOWTITLEBAR_H #include <QLabel> #include <QPainter> #include <QPixmap> #include <QWidget> #include "buttons/minimizebutton.h" class WindowTitleBar : public QWidget { Q_OBJECT public: WindowTitleBar(QWidget *parent = 0); ~WindowTitleBar(); protected: void resizeEvent(QResizeEvent *event); void paintEvent(QPaintEvent *event); private: QLabel *m_Title; QPixmap *m_Cache; MinimizeButton *m_Minimize; public slots: void UpdateWindowTitle(); void Minimized(); void Maximized(); void Quit(); }; #endif // WINDOWTITLEBAR_H |
Le code de minimizebutton.cpp :
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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | #include "minimizebutton.h" MinimizeButton::MinimizeButton() { } void WindowTitleBar::resizeEvent(QResizeEvent *event) { Q_UNUSED(event); /********** Button's border **********/ QPolygon border; border << QPoint(0, 0) << QPoint(29, 0) << QPoint(29, 22) << QPoint(0, 22); /*************************************/ /********** Button's symbol **********/ QPolygon symbol; symbol << QPoint(9, 12) << QPoint(18, 12) << QPoint(18, 14) << QPoint(9, 14); /*************************************/ QPainter painter; /********** Normal **********/ painter.begin(m_Normal); painter.setBrush(Qt::transparent); painter.setPen(Qt::NoPen); painter.drawPolygon(border); painter.setBrush(QBrush(QColor(119, 119, 119))); painter.setPen(Qt::NoPen); painter.drawPolygon(symbol); painter.end(); /****************************/ /********** Hovered **********/ painter.begin(m_Hovered); painter.setPen(Qt::NoPen); painter.setBrush(QBrush(QColor(213, 225, 242))); painter.drawPolygon(border); painter.setPen(Qt::NoPen); painter.setBrush(QBrush(QColor(62, 109, 181))); painter.drawPolygon(symbol); painter.end(); /*****************************/ /********** Clicked **********/ painter.begin(m_Clicked); painter.setPen(Qt::NoPen); painter.setBrush(QBrush(QColor(163, 189, 227))); painter.drawPolygon(border); painter.setPen(Qt::NoPen); painter.setBrush(QBrush(QColor(25, 71, 138))); painter.drawPolygon(symbol); painter.end(); /*****************************/ } void WindowButton::paintEvent(QPaintEvent *event) { Q_UNUSED(event); QPainter painter(this); if(isEnabled()) { switch(m_State) { case STATE_NORMAL: if(m_Normal != NULL) painter.drawPixmap(0, 0, *m_Normal); break; case STATE_HOVERED: if(m_Hovered != NULL) painter.drawPixmap(0, 0, *m_Hovered); break; case STATE_CLICKED: if(m_Clicked != NULL) painter.drawPixmap(0, 0, *m_Clicked); break; } } else { if(m_Normal != NULL) painter.drawPixmap(0, 0, *m_Normal); } } void WindowButton::enterEvent(QEvent *event) { Q_UNUSED(event); m_State = STATE_HOVERED; update(); } void WindowButton::leaveEvent(QEvent *event) { Q_UNUSED(event); m_State = STATE_NORMAL; update(); } void WindowButton::mousePressEvent(QMouseEvent *event) { QAbstractButton::mousePressEvent(event); m_State = STATE_CLICKED; emit Click(); update(); } void WindowButton::mouseReleaseEvent(QMouseEvent *event) { QAbstractButton::mouseReleaseEvent(event); if(underMouse()) { m_State = STATE_HOVERED; } else { m_State = STATE_NORMAL; } update(); } |
Et le code de minimizebutton.h :
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 | #ifndef MINIMIZEBUTTON_H #define MINIMIZEBUTTON_H #include <QPixmap> #include <QPolygon> class MinimizeButton { Q_OBJECT public: MinimizeButton(); protected: void resizeEvent(QResizeEvent *event); private: enum ButtonState{STATE_NORMAL, STATE_HOVERED, STATE_CLICKED}; ButtonState m_State; QPixmap *m_Normal; QPixmap *m_Hovered; QPixmap *m_Clicked; signals: void Click(); }; #endif // MINIMIZEBUTTON_H |
Merci d'avance
+0
-0