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. QWidget subclass does not appear on main window.
Forum Updated to NodeBB v4.3 + New Features

QWidget subclass does not appear on main window.

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 702 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #2

    You have to add it to your layout. Best here is, since you're already using a ui file, to promote your widget in designer.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    clostridium_difficileC 1 Reply Last reply
    1
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #3

      Hi
      Its just invisible as the stylesheet is not applied.

      try adding

      protected:
          virtual void paintEvent(QPaintEvent *event) override
          {
              QPainter p(this);
              p.drawRect(0, 0, width() - 1, height() - 1);
          }
      

      and you see its there.

      1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        You have to add it to your layout. Best here is, since you're already using a ui file, to promote your widget in designer.

        clostridium_difficileC Offline
        clostridium_difficileC Offline
        clostridium_difficile
        wrote on last edited by
        #4

        @Christian-Ehrlicher I added widget to mainwindow and promoted it to ToolBar, but still it isn't visible

        Christian EhrlicherC 1 Reply Last reply
        0
        • clostridium_difficileC clostridium_difficile

          @Christian-Ehrlicher I added widget to mainwindow and promoted it to ToolBar, but still it isn't visible

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #5

          @clostridium_difficile The move(50, 100) is useless / counter-productive. Please show us your current code.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          clostridium_difficileC 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @clostridium_difficile The move(50, 100) is useless / counter-productive. Please show us your current code.

            clostridium_difficileC Offline
            clostridium_difficileC Offline
            clostridium_difficile
            wrote on last edited by clostridium_difficile
            #6

            @Christian-Ehrlicher current code? I showed you my current code in my first post in this topic and nothing changed. Widget has been promoted in Qt Designer. I moved toolbar to (50, 100), since I wanted to see what happens.
            @mrjj i applied style sheet in line

            setStyleSheet("background-color: #123456;");
            
            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #7

              @clostridium_difficile said in QWidget subclass does not appear on main window.:

              I showed you my current code in my first post in this topic and nothing changed.

              So now you're instantiating the class two times? One in the ui and one in the ctor? How should this ever work?

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              clostridium_difficileC 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @clostridium_difficile said in QWidget subclass does not appear on main window.:

                I showed you my current code in my first post in this topic and nothing changed.

                So now you're instantiating the class two times? One in the ui and one in the ctor? How should this ever work?

                clostridium_difficileC Offline
                clostridium_difficileC Offline
                clostridium_difficile
                wrote on last edited by
                #8

                @Christian-Ehrlicher it it possible to have multiple instancens of the same widget type. I know what you mean – I didn't deleted ToolBar * toolBar; in Mainwindow – don't you? Apparently, it works for some reason – had two instances of this widget. I deleted it now, with initialization in constructor, but left only one instance, and nothing more has changed.

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  So now you can access your toolbar with 'ui->toolbar'? Please reimplement the paint event as suggested by @mrjj and fill your widget with e.g. a red color.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  clostridium_difficileC 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    So now you can access your toolbar with 'ui->toolbar'? Please reimplement the paint event as suggested by @mrjj and fill your widget with e.g. a red color.

                    clostridium_difficileC Offline
                    clostridium_difficileC Offline
                    clostridium_difficile
                    wrote on last edited by
                    #10

                    @Christian-Ehrlicher I've did it already. I see frame. Ok, thats what I wanted to achieve, but why setStyleSheet does not work?

                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      @clostridium_difficile said in QWidget subclass does not appear on main window.:

                      but why setStyleSheet does not work?

                      I would guess because autoFillBackground is not set to true.

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      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