Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    New Qwidget

    Mobile and Embedded
    3
    5
    5912
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      tristenn last edited by

      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

      1 Reply Last reply Reply Quote 0
      • T
        tristenn last edited by

        nothing showed.

        1 Reply Last reply Reply Quote 0
        • A
          alexander last edited by

          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;
          }@

          1 Reply Last reply Reply Quote 0
          • F
            Franzk last edited by

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

            "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

            1 Reply Last reply Reply Quote 0
            • ?
              Guest last edited by

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

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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post