November 8, 2010

tristenn tristenn
Lab Rat
25 posts

new Qwidget

 

Hi, can tell me pls anybody, whats wrong with this code :

  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3.  
  4. MainWindow::MainWindow(QWidget *parent) :
  5.     QMainWindow(parent),
  6.     ui(new Ui::MainWindow)
  7. {
  8.  
  9.     ui->setupUi(this);
  10.  
  11.     QWidget *datawidget;
  12.  
  13.     datawidget = new QWidget();
  14.     datawidget->setAccessibleName("datawidget");
  15.     datawidget->setParent(ui->centralWidget);
  16.     datawidget->resize(30,30);
  17.     datawidget->setStyleSheet(" #datawidget { background-color:#000; } ");
  18.     datawidget->show();
  19.     datawidget->setVisible(true);
  20. }
  21.  
  22. MainWindow::~MainWindow()
  23. {
  24.     delete ui;
  25. }

Thanks

4 replies

November 8, 2010

tristenn tristenn
Lab Rat
25 posts

nothing showed.

November 8, 2010

Alexander Kuchumov Alexander Kuchumov
Lab Rat
380 posts

Try this:

  1. MainWindow::MainWindow(QWidget *parent) :
  2.     QMainWindow(parent),
  3.     ui(new Ui::MainWindow)
  4. {
  5.  
  6.     ui->setupUi(this);
  7.  
  8.     QWidget *datawidget = new QWidget( this );
  9.     ui->setCentralWidget( datawidget );
  10.     datawidget->setAccessibleName("datawidget");
  11.     datawidget->setStyleSheet(" #datawidget { background-color:#000; } ");
  12. }
  13.  
  14. MainWindow::~MainWindow()
  15. {
  16.     delete ui;
  17. }

November 8, 2010

Franzk Franzk
Lab Rat
840 posts

If you used a layout for your ui, you (c|sh)ould add the new widget to the layout.

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

November 8, 2010

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts

Problem is with your setStyleSheet call … use this instead

  1. datawidget->setStyleSheet(" { background-color:#000; } ");

 
  ‹‹ how to Get the Children of Tool Bar ?      [Solved] QTextEdit bug on Symbian S60v5? ››

You must log in to post a reply. Not a member yet? Register here!