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. My ScoreBoard inherits QMainWindow()
Qt 6.11 is out! See what's new in the release blog

My ScoreBoard inherits QMainWindow()

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 5.7k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    RichardM198030
    wrote on last edited by
    #1

    Hello.. Not to sound vague, but what is it with this TK? I keep getting this warning about trying to add a layout to class ScoreBoard when it already has one, a friend discovered that QMainWindow() has a special layout, he said to get rid of this warning is to create a CentralWidget of QWidget type, then add my Layout to that widget, did this, still getting same warning, can somebody explain a different way?

    [code]

    /* ScoreBoard QMainWindow() */

    QWidget *cw; // cw == Central Widget

    cw = new QWidget(this);

    setCentralWidget(cw);

    cw->setLayout(mainLayout); // Note: Not looking at my source, cannot remember where I put it earlier when I got that Seg Fault, I'm not mistaken, this is the proper location.

    [/code]

    [code]

    /* The Layout code for QMainWindow */

    QVBoxLayout *mainLayout;
    mainLayout = new QVBoxLayout(this);

    [/code]

    Thanks for the help.

    [edit : fixed typo in title, Eddy]

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mkoskim
      wrote on last edited by
      #2

      Yes, QMainWindow already has a layout, which contains places for different elements (central widget, menu bar, status bar, north/south/east/west areas etc).

      To show something in main window, you create a widget, and place it to main window with functions like [url=http://doc.qt.nokia.com/stable/qmainwindow.html#setCentralWidget]setCentralWidget()[/url], [url=http://doc.qt.nokia.com/stable/qmainwindow.html#setCorner]setCorner()[/url], and so on.

      http://mkoskim.wordpress.com
      http://mkoskim.drivehq.com
      http://mkoskim.deviantart.com

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RichardM198030
        wrote on last edited by
        #3

        [quote author="mkoskim" date="1319199023"]Yes, QMainWindow already has a layout, which contains places for different elements (central widget, menu bar, status bar, north/south/east/west areas etc).

        To show something in main window, you create a widget, and place it to main window with functions like setCentralWidget(), setCorner(), and so on.
        [/quote]

        I'm trying to create my own custom Layout for advanced features..

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mkoskim
          wrote on last edited by
          #4

          [quote author="RichardM198030" date="1319199139"]
          I'm trying to create my own custom Layout for advanced features..[/quote]

          You create the layout to your custom widget, and place that widget to main window:

          [code]
          QWidget *mainwidget = new QWidget;
          mainwidget->setLayout(new MyCustomLayout);

          mainwindow->setCentralWidget(mainwidget);
          [/code]

          http://mkoskim.wordpress.com
          http://mkoskim.drivehq.com
          http://mkoskim.deviantart.com

          1 Reply Last reply
          0
          • R Offline
            R Offline
            RichardM198030
            wrote on last edited by
            #5

            [quote author="mkoskim" date="1319199272"][quote author="RichardM198030" date="1319199139"]
            I'm trying to create my own custom Layout for advanced features..[/quote]

            You create the layout to your custom widget, and place that widget to main window:

            [code]
            QWidget *mainwidget = new QWidget;
            mainwidget->setLayout(new MyCustomLayout);

            mainwindow->setCentralWidget(mainwidget);
            [/code][/quote]

            Oooh, so I have to create 2 QWidgets then?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mkoskim
              wrote on last edited by
              #6

              [quote author="RichardM198030" date="1319199600"]
              Oooh, so I have to create 2 QWidgets then?
              [/quote]

              Yes, you create one QMainWindow, and you place your custom QWidget on it (QMainWindow::setCentralWidget, except if you want to place your custom widget to e.g. some dockable areas).

              http://mkoskim.wordpress.com
              http://mkoskim.drivehq.com
              http://mkoskim.deviantart.com

              1 Reply Last reply
              0
              • R Offline
                R Offline
                RichardM198030
                wrote on last edited by
                #7

                [quote author="mkoskim" date="1319200495"][quote author="RichardM198030" date="1319199600"]
                Oooh, so I have to create 2 QWidgets then?
                [/quote]

                Yes, you create one QMainWindow, and you place your custom QWidget on it (QMainWindow::setCentralWidget, except if you want to place your custom widget to e.g. some dockable areas).[/quote]

                LOL, sorry, I confused ya, I meant, I have to make 1 QWidget *cw; and a 2Nd QWidget *mainWIdget?

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mkoskim
                  wrote on last edited by
                  #8

                  [quote author="RichardM198030" date="1319200911"]
                  LOL, sorry, I confused ya, I meant, I have to make 1 QWidget *cw; and a 2Nd QWidget *mainWIdget?
                  [/quote]

                  No, one widget is enough. You place it to your main window. This is a wild guess, but what if you inherit your ScoreBoard from QWidget, and use just plain QMainWindow to show it?

                  [code]
                  class ScoreBoard : public QWidget { ... }

                  ...
                  main()
                  {
                  QMainWindow *mainwindow = new QMainWindow;
                  mainwindow->setCentralWidget(new ScoreBoard);
                  ...
                  }
                  [/code]

                  http://mkoskim.wordpress.com
                  http://mkoskim.drivehq.com
                  http://mkoskim.deviantart.com

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    RichardM198030
                    wrote on last edited by
                    #9

                    [quote author="mkoskim" date="1319202757"][quote author="RichardM198030" date="1319200911"]
                    LOL, sorry, I confused ya, I meant, I have to make 1 QWidget *cw; and a 2Nd QWidget *mainWIdget?
                    [/quote]

                    No, one widget is enough. You place it to your main window. This is a wild guess, but what if you inherit your ScoreBoard from QWidget, and use just plain QMainWindow to show it?

                    [code]
                    class ScoreBoard : public QWidget { ... }

                    ...
                    main()
                    {
                    QMainWindow *mainwindow = new QMainWindow;
                    mainwindow->setCentralWidget(new ScoreBoard);
                    ...
                    }
                    [/code]
                    [/quote]

                    Just came with something different too.. I can keep my cw widget, make a mainwidget, add the layout to mainwidget, add the mainwidget to cw, and add cw to the ScoreBoard class, =).

                    1 Reply Last reply
                    0

                    • Login

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