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. Resize a QDockWidget width ?
Qt 6.11 is out! See what's new in the release blog

Resize a QDockWidget width ?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.4k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi,
    I have a problem with my QDockWidget, I want it to take all available width space. But it only takes the minimum space...

    This is the source code that I do :

    [CODE]//testWidget.h
    class testWidget : public QWidget
    {
    Q_OBJECT

    public:
    explicit testWidget(QWidget *parent = 0);
    QLabel test;
    QPushButton testButton;

    };[/CODE]

    [CODE]//testWidget.cpp
    testWidget::testWidget(QWidget *parent) :
    QWidget(parent)
    {
    setStyleSheet("background-color: yellow");

    test.setText("test label");
    test.setParent(this);
    test.setVisible(true);
    
    testButton.setText("TestButton");
    testButton.setParent(this);
    testButton.move(0, 20);
    testButton.setVisible(true);
    

    }[/CODE]

    [CODE]//mainWindow.h
    class mainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit mainWindow(QWidget *parent = 0);
    testWidget *testW;
    };[/CODE]

    [CODE]//mainWindow.cpp
    mainWindow::mainWindow(QWidget *parent)
    : QMainWindow(parent)
    {
    setFixedSize(1000, 900);

    QLabel *test = new QLabel;
    test->setFixedSize(500,900);
    test->setStyleSheet("background-color: black;");
    setCentralWidget(test);
    
    testW = new testWidget;
    
    QDockWidget *dock = new QDockWidget("DOCKTEST", this);
    dock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
    dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    dock->setWidget(testW);
    addDockWidget(Qt::RightDockWidgetArea, dock);
    

    }[/CODE]

    The result is:
    !http://image.noelshack.com/fichiers/2012/17/1335632129-Capturedu2012-04-28185448.png(result)!

    And I want that :
    !http://image.noelshack.com/fichiers/2012/17/1335632129-Capturedu2012-04-28185455.png(i want)!

    So, if someone can help me, it will be very great !

    Thanks in advance for your help,

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      You need to implement the sizeHint() function in your custom widget and use a sensible sizePolicy that will give you the layout that you want.

      If you are not locked into using a dock widget then a QSplitter might be an easier way.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        You need to use Qt layout functionality if you want Qt to do anything to layout/resize the content of your widgets.

        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