New Qwidget



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

    @#include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {

    ui->setupUi(this);
    
    QWidget *datawidget;
    
    datawidget = new QWidget();
    datawidget->setAccessibleName("datawidget");
    datawidget->setParent(ui->centralWidget);
    datawidget->resize(30,30);
    datawidget->setStyleSheet(" #datawidget { background-color:#000; } ");
    datawidget->show();
    datawidget->setVisible(true);
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }
    @

    Thanks



  • nothing showed.



  • Try this:
    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {

    ui->setupUi(this);
    
    QWidget *datawidget = new QWidget( this );
    ui->setCentralWidget( datawidget );
    datawidget->setAccessibleName("datawidget");
    datawidget->setStyleSheet(" #datawidget { background-color:#000; } ");
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }@



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



  • Problem is with your setStyleSheet call ... use this instead

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.