Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Custom widget can't show in layout
Forum Updated to NodeBB v4.3 + New Features

Custom widget can't show in layout

Scheduled Pinned Locked Moved Solved Qt 6
3 Posts 3 Posters 352 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.
  • J Offline
    J Offline
    jjjkk
    wrote on last edited by
    #1

    I code a custom widget and put it in the main layout in my mainwindow class .
    But It can't show properly as below:
    dbdd7e4c-aa7d-4e4a-aa96-c99f22367dab-image.png
    the blank part should be the custom widget.
    I change the code generate by ui file from:

            graphicsView = new MainViewer(aaa);
            graphicsView->setObjectName(QString::fromUtf8("graphicsView"));
    
            gridLayout->addWidget(graphicsView, 3, 1, 1, 1);
    
            MainWindow->setCentralWidget(aaa);
    

    to:

            graphicsView = new MainViewer(aaa);
            graphicsView->setObjectName(QString::fromUtf8("graphicsView"));
    
            //gridLayout->addWidget(graphicsView, 3, 1, 1, 1);
    
            MainWindow->setCentralWidget(aaa);
    

    I can get a floating custom widget as below:
    64f218d8-f822-492e-8533-d31fc335ad9c-image.png
    And if I set the custom widget as central widget, It also work well.

    So, what may be the problem when I put the custom widget into a layout?

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

      Hi
      There is no special requirements for a custom widget to be used in a layout but maybe it get compressed to zero in size
      so try for test to do
      mywidget->setMinimumSize(100,100) and see.

      1 Reply Last reply
      1
      • JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by
        #3

        void QGridLayout::addWidget(QWidget *widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment = Qt::Alignment())

        gridLayout->addWidget(graphicsView, 1, 0, 3, 1);

        1 Reply Last reply
        1

        • Login

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