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. How to make QWidget fill parent QWidget?
Forum Updated to NodeBB v4.3 + New Features

How to make QWidget fill parent QWidget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 662 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.
  • K Offline
    K Offline
    kitfox
    wrote on last edited by kitfox
    #1

    I'm having trouble getting a child QWidget to fill it's parent. I've created a form using QtDesigner and added some QWidgets to it - the idea is that I want to fill these empty rectangles with custom QWidgets. In the constructor for my form, I am creating an instance of my child widget and adding it and a layout to the placeholder QWidget I have in my form, but no matter what I try my child widget is only filling a small portion in the top left corner of the widget I want it to fill entirely. How do I fix this?

    sequencereditor.h

    #ifndef __SEQUENCER_EDITOR_H__
    #define __SEQUENCER_EDITOR_H__
    
    #include "ui_sequencereditor.h"
    
    class SequencerNames;
    
    class SequencerEditor : public QDockWidget, public Ui::SequencerEditor
    {
        Q_OBJECT
    
        Score* _score;
        SequencerNames* _seqNames;
    
    public:
        explicit SequencerEditor(QWidget *parent = nullptr);
        ~SequencerEditor();
    };
    
    #endif // __SEQUENCER_EDITOR_H__
    

    sequenceredtior.cpp

    #include "sequencereditor.h"
    
    #include "sequencernames.h"
    
    SequencerEditor::SequencerEditor(QWidget *parent) :
        QDockWidget(qApp->translate("Sequencer", "Sequencer"), parent)
    {
        setupUi(this);
    
        QHBoxLayout* nameAreaLayout = new QHBoxLayout(nameArea);
    
        _seqNames = new SequencerNames(nameArea);
    
    //    _seqNames->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    
        nameAreaLayout->addWidget(_seqNames);
    }
    
    SequencerEditor::~SequencerEditor()
    {
    }
    
    

    sequencernames.h

    #ifndef __SEQUENCER_NAMES_H__
    #define __SEQUENCER_NAMES_H__
    
    
    
    class SequencerNames : public QWidget
    {
        Q_OBJECT
    
    public:
        SequencerNames(QWidget* parent = nullptr);
    
    private:
        virtual void paintEvent(QPaintEvent*);
    
    };
    
    #endif // SEQUENCERNAMES_H
    
    

    sequencernames.cpp

    #include "sequencernames.h"
    
    SequencerNames::SequencerNames(QWidget* parent) :
        QWidget(parent)
    {
    
    }
    
    //---------------------------------------------------------
    //   paintEvent
    //---------------------------------------------------------
    
    void SequencerNames::paintEvent(QPaintEvent* /*event*/)
    {
        QPainter p(this);
        p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing);
    
        p.setPen(Qt::red);
        p.drawEllipse(0, 0, width(), height());
    }
    
    
    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on last edited by Bonnie
      #2

      What is "nameArea"?
      I think you need to post sequencereditor.ui, too.
      Also, although I'm not familiar with QDockWidget, but I think the usual way is not subclassing it, but calling setWidget()

      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