Changeset 304 for tests/widget/widget.cpp
- Timestamp:
- Nov 8, 2009, 10:57:37 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/widget/widget.cpp
r300 r304 62 62 } 63 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 64 118 class MyButton : public QPushButton 65 119 { … … 68 122 MyButton(QWidget *aParent) : QPushButton(aParent) {} 69 123 124 70 125 void focusInEvent(QFocusEvent *aE) 71 126 { 72 #if 0 73 qDebug() << __FUNCTION__ << ":" << text()<< "reason" << aE->reason()127 qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << text() 128 << "reason" << aE->reason() 74 129 << "focus" << (qApp->focusWidget() ? 75 130 qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>"))); 76 #endif 131 132 QPushButton::focusInEvent(aE); 77 133 } 78 134 79 135 void focusOutEvent(QFocusEvent *aE) 80 136 { 81 #if 0 82 qDebug() << __FUNCTION__ << ":" << text()<< "reason" << aE->reason()137 qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << text() 138 << "reason" << aE->reason() 83 139 << "focus" << (qApp->focusWidget() ? 84 140 qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>"))); 85 #endif 86 } 141 QPushButton::focusOutEvent(aE); 142 } 143 #endif 87 144 }; 88 145 146 147 148 89 149 class MyCombo : public QComboBox 90 150 { … … 93 153 MyCombo(QWidget *aParent) : QComboBox(aParent) {} 94 154 155 95 156 void focusInEvent(QFocusEvent *aE) 96 157 { 97 update(); 98 #if 0 99 qDebug() << __FUNCTION__ << ":" << currentText() << "reason" << aE->reason() 158 qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << currentText() 159 << "reason" << aE->reason() 100 160 << "focus" << (qApp->focusWidget() ? 101 161 qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>"))); 102 #endif 162 QComboBox::focusInEvent(aE); 103 163 } 104 164 105 165 void focusOutEvent(QFocusEvent *aE) 106 166 { 107 update(); 108 #if 0 109 qDebug() << __FUNCTION__ << ":" << currentText() << "reason" << aE->reason() 167 qDebug() << qWidgetName(this) << __FUNCTION__ << ":" << currentText() 168 << "reason" << aE->reason() 110 169 << "focus" << (qApp->focusWidget() ? 111 170 qWidgetName(qApp->focusWidget()) : QDbgStr(QLatin1String("<none>"))); 112 #endif 113 } 171 QComboBox::focusOutEvent(aE); 172 } 173 #endif 114 174 115 175 #if 0 … … 169 229 }; 170 230 231 232 171 233 class MyWidget : public QWidget 172 234 { 173 235 public: 174 236 175 MyWidget() 176 { 177 //setFocusPolicy(Qt::StrongFocus);178 179 //MyButton *btn1 = new MyButton(this);180 //btn1->setText(QLatin1String("Hello 1"));181 //btn1->setObjectName("Hello 1");182 //btn1->move(20, 20);183 //MyButton *btn2 = new MyButton(this);184 //btn2->setText(QLatin1String("Hello 2"));185 //btn2->setObjectName("Hello 2");186 //btn2->move(20, 60);187 188 189 190 237 MyWidget() 238 { 239 setFocusPolicy(Qt::StrongFocus); 240 241 MyButton *btn1 = new MyButton(this); 242 btn1->setText(QLatin1String("Hello 1")); 243 btn1->setObjectName("Hello 1"); 244 btn1->move(20, 20); 245 MyButton *btn2 = new MyButton(this); 246 btn2->setText(QLatin1String("Hello 2")); 247 btn2->setObjectName("Hello 2"); 248 btn2->move(20, 60); 249 250 QComboBox *cb1 = new MyCombo(this); 251 cb1->addItem(QLatin1String("Test 1")); 252 cb1->addItem(QLatin1String("Test 2")); 191 253 192 254 // QComboBox *cb2 = new MyCombo(this); … … 194 256 // cb2->addItem(QLatin1String("Test 4")); 195 257 196 258 QVBoxLayout *mainLayout = new QVBoxLayout(); 197 259 // mainLayout->addWidget(btn1); 198 260 // mainLayout->addWidget(btn2); 199 261 mainLayout->addWidget(cb1); 200 262 // mainLayout->addWidget(cb2); 201 263 202 setLayout(mainLayout); 264 // setLayout(mainLayout); 265 266 #if 0 267 new MyChild(this); 268 #endif 269 203 270 }; 204 271 … … 211 278 p.setRenderHint(QPainter::Antialiasing); 212 279 213 p.fillRect(0, 0, 20, 20, Qt::green);280 p.fillRect(0, 0, 20, 20, Qt::green); 214 281 215 282 p.setPen(Qt::black); … … 238 305 void focusInEvent(QFocusEvent *aE) 239 306 { 240 qDebug() << __FUNCTION__ << ": reason" << aE->reason(); 307 qDebug() << qWidgetName(this) << __FUNCTION__ << ": reason" << aE->reason(); 308 QWidget::focusInEvent(aE); 241 309 } 242 310 243 311 void focusOutEvent(QFocusEvent *aE) 244 312 { 245 qDebug() << __FUNCTION__ << ": reason" << aE->reason(); 313 qDebug() << qWidgetName(this) << __FUNCTION__ << ": reason" << aE->reason(); 314 QWidget::focusOutEvent(aE); 246 315 } 247 316 #endif … … 286 355 287 356 #if 0 288 void mouse MoveEvent(QMouseEvent *aE)357 void mouseEvent(QMouseEvent *aE) 289 358 { 290 359 qDebug() << __FUNCTION__ << ": btn" << aE->button() … … 292 361 (int) aE->buttons(), (int) aE->modifiers())) 293 362 << "gpos" << aE->globalPos() << "pos" << aE->pos(); 294 } 295 296 void mousePressEvent(QMouseEvent *aE) 363 364 ++mPressed; 365 update(); 366 } 367 368 void mouseReleaseEvent(QMouseEvent *aE) 297 369 { 298 370 qDebug() << __FUNCTION__ << ": btn" << aE->button() … … 302 374 } 303 375 304 void mouse ReleaseEvent(QMouseEvent *aE)376 void mouseeEvent(QMouseEvent *aE) 305 377 { 306 378 qDebug() << __FUNCTION__ << ": btn" << aE->button() … … 339 411 } 340 412 #endif 413 414 415 416 341 417 }; 342 418 … … 347 423 MyWidget widget; 348 424 widget.resize(100, 100); 349 widget.move( 500, 500);425 widget.move(00); 350 426 351 427 widget.show(); 352 353 #if 1428 429 #if 354 430 { 355 431 QFontDialog fntDlg; 356 432 fntDlg.exec(); 357 433 358 434 { 359 435 QFont font("MyCoolFont"); … … 399 475 return app.exec(); 400 476 } 477 478
Note:
See TracChangeset
for help on using the changeset viewer.