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. A custom widget which inherited from QMainwindow can't display in Preview of Qt Desinger
Forum Update on Monday, May 27th 2025

A custom widget which inherited from QMainwindow can't display in Preview of Qt Desinger

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 612 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.
  • T Offline
    T Offline
    Toocold
    wrote on last edited by
    #1
    • The custom widget displays well in qt designer, but can't work well in the preview.
      IPY3V{4Z%2F~PUUNB_TR$X4.png

    • Whereas it will work well when I change the inherited parent from QMainwindow to Qwidget.

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

      Did you create a designer plugin or how did you use it 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

      T 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        Did you create a designer plugin or how did you use it in designer?

        T Offline
        T Offline
        Toocold
        wrote on last edited by
        #3

        @Christian-Ehrlicher I created this designer plugin by QDesignerCustomWidgetInterface. And It was available when the custom widget inherited from QWidget instead of QMainWindow.

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

          Then make sure you defined all correct when you changed from QWidget to QMainWindow.

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

          T 2 Replies Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            Then make sure you defined all correct when you changed from QWidget to QMainWindow.

            T Offline
            T Offline
            Toocold
            wrote on last edited by
            #5

            @Christian-Ehrlicher Well. You can see the mainwindow display in the .ui File after the window of Preview, and the tabs and menu works well, but once in the Preview i can't see the mainwindow. And In my code, this custom widget change from QWidget to QMainWindow just need to modify its parent, i don't think i had defined something wrong. Does the plugin mechanism have some rules that can't display a QMainwindow in the Preview?

            1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              Then make sure you defined all correct when you changed from QWidget to QMainWindow.

              T Offline
              T Offline
              Toocold
              wrote on last edited by
              #6

              @Christian-Ehrlicher And after I test other widgets, I found QPushButton, QLineEdit.. which in the widget box of qt designer is ok, but like QMainWindow, QMenubar.., they all can display in the qt desginer and can't work in Preview. So that means qt designer can't preview the custom widget which inherits these? Is it a bug or something? Because if these widgets combined in a intance inherited from QWidget, they are ok in the Preview.

              jsulmJ Christian EhrlicherC 2 Replies Last reply
              0
              • T Toocold

                @Christian-Ehrlicher And after I test other widgets, I found QPushButton, QLineEdit.. which in the widget box of qt designer is ok, but like QMainWindow, QMenubar.., they all can display in the qt desginer and can't work in Preview. So that means qt designer can't preview the custom widget which inherits these? Is it a bug or something? Because if these widgets combined in a intance inherited from QWidget, they are ok in the Preview.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7
                This post is deleted!
                1 Reply Last reply
                0
                • T Toocold

                  @Christian-Ehrlicher And after I test other widgets, I found QPushButton, QLineEdit.. which in the widget box of qt designer is ok, but like QMainWindow, QMenubar.., they all can display in the qt desginer and can't work in Preview. So that means qt designer can't preview the custom widget which inherits these? Is it a bug or something? Because if these widgets combined in a intance inherited from QWidget, they are ok in the Preview.

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

                  @Toocold I don't have problems with previewing custom widgets added with a correct designer plugin. Please provide a minimal, compilable example of your plugin.

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

                  T 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    @Toocold I don't have problems with previewing custom widgets added with a correct designer plugin. Please provide a minimal, compilable example of your plugin.

                    T Offline
                    T Offline
                    Toocold
                    wrote on last edited by
                    #9

                    @Christian-Ehrlicher

                    QWidget* TestPlugin::createWidget(QWidget* pParent)
                    {
                        auto pTestWidget = new QWidget(pParent);
                        auto pTestButton = new QPushButton(pTestWidget);
                        pTestButton->setText("Hello");
                        return pTestWidget;
                    }
                    

                    Hey, use above code can easily to see a custom widget named "QWidget" previewing in the qt designer.

                    QWidget* TestPlugin::createWidget(QWidget* pParent)
                    {
                        auto pTestWidget = new QMenuBar(pParent);
                        auto pTestMenu = pTestWidget->addMenu("Hello");
                        pTestMenu->addMenu("World");
                        return pTestWidget;
                    }
                    

                    And if you use the next code block, and modify the domxml(), name().., you can see it in you qt designer but won't preview, same as QMainWindow.

                    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