Guest User

strange widget problem

a guest
Nov 24th, 2011
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // mywidget.h
  3.  
  4. #ifndef MYWIDGET_H
  5. #define MYWIDGET_H
  6.  
  7. #include <QWidget>
  8.  
  9. class MyWidget : public QWidget
  10. {
  11.     Q_OBJECT
  12. public:
  13.     explicit MyWidget(QWidget *parent = 0);
  14.  
  15. signals:
  16.  
  17. public slots:
  18.  
  19. };
  20.  
  21. #endif // MYWIDGET_H
  22.  
  23.  
  24. //---------------------------------------------------------------------------------------
  25.  
  26.  
  27. // mywidget.cpp
  28. #include "mywidget.h"
  29.  
  30. MyWidget::MyWidget(QWidget *parent) :
  31.     QWidget(parent)
  32. {
  33. }
  34.  
  35.  
  36. //---------------------------------------------------------------------------------------
  37.  
  38.  
  39. // mainwindow.h
  40. #ifndef MAINWINDOW_H
  41. #define MAINWINDOW_H
  42.  
  43. #include <QMainWindow>
  44.  
  45. namespace Ui {
  46.     class MainWindow;
  47. }
  48.  
  49. class MainWindow : public QMainWindow
  50. {
  51.     Q_OBJECT
  52.  
  53. public:
  54.     explicit MainWindow(QWidget *parent = 0);
  55.     ~MainWindow();
  56.  
  57. private:
  58.     Ui::MainWindow *ui;
  59. };
  60.  
  61. #endif // MAINWINDOW_H
  62.  
  63.  
  64. //---------------------------------------------------------------------------------------
  65.  
  66.  
  67. // mainwindow.cpp
  68.  
  69. #include "mainwindow.h"
  70. #include "ui_mainwindow.h"
  71. #include "mywidget.h"
  72.  
  73. MainWindow::MainWindow(QWidget *parent) :
  74.     QMainWindow(parent),
  75.     ui(new Ui::MainWindow)
  76. {
  77.     ui->setupUi(this);
  78. //  QWidget *w = new MyWidget(this);    // this line is ok
  79.     MyWidget *w = new MyWidget(this);   // but this one is not
  80.     w->setGeometry(10,20,100,100);
  81.     w->setStyleSheet("background-color:white;");
  82.     w->show();
  83. }
  84.  
  85. MainWindow::~MainWindow()
  86. {
  87.     delete ui;
  88. }
  89.  
  90.  
Advertisement
Add Comment
Please, Sign In to add comment