Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. If I want to use "setCentralWidget" in Widget, what should I do.

If I want to use "setCentralWidget" in Widget, what should I do.

Scheduled Pinned Locked Moved Unsolved General and Desktop
qcustomplot
5 Posts 3 Posters 513 Views
  • 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.
  • S Offline
    S Offline
    Sabual
    wrote on 29 May 2021, 13:48 last edited by
    #1

    I am now porting the sample code of QCustomPlot. The sample code of QCustomPlot uses QMainWindow, and I want to use QWidget. What should I do?

    this is my code

    Widget::Widget(QWidget *parent)
        : QWidget(parent)
        , ui(new Ui::Widget),
          mPlot(0),
          mTag1(0),
          mTag2(0)
    {
        ui->setupUi(this);
    
        mPlot = new QCustomPlot(this);
        setCentralWidget(mPlot);
    }
    

    this is QCustomPlot`s sample code

    MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow),
      mPlot(0),
      mTag1(0),
      mTag2(0)
    {
      ui->setupUi(this);
      
      mPlot = new QCustomPlot(this);
      setCentralWidget(mPlot);
    }
    

    Please help me!😭😭

    1 Reply Last reply
    0
    • S Offline
      S Offline
      skycrestway
      wrote on 29 May 2021, 14:18 last edited by
      #2

      You can only use setCentralWidget with a QMainWindow. Instead use QWidget::setLayout to add a layout and then add a QWidget to the layout.

      See the documentation for QWidget::setLayout.

      1 Reply Last reply
      4
      • S Offline
        S Offline
        Sabual
        wrote on 29 May 2021, 16:02 last edited by
        #3

        The QWidget is a separate ‘.ui’ file.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 29 May 2021, 18:34 last edited by
          #4

          Hi and welcome to devnet,

          The answer of @skycrestway still holds. Your widget needs a layout. After that you can add your plot to that layout.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply 30 May 2021, 14:51
          1
          • S SGaist
            29 May 2021, 18:34

            Hi and welcome to devnet,

            The answer of @skycrestway still holds. Your widget needs a layout. After that you can add your plot to that layout.

            S Offline
            S Offline
            Sabual
            wrote on 30 May 2021, 14:51 last edited by
            #5

            @SGaist oh!i know,thanks!

            1 Reply Last reply
            0

            5/5

            30 May 2021, 14:51

            • Login

            • Login or register to search.
            5 out of 5
            • First post
              5/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved