Results 1 to 6 of 6

Thread: Resize a QDockWidget ? (Width)

  1. #1
    Join Date
    Jan 2011
    Posts
    19
    Thanks
    4

    Default Resize a QDockWidget ? (Width)

    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 :

    Qt Code:
    1. //testWidget.h
    2. class testWidget : public QWidget
    3. {
    4. Q_OBJECT
    5.  
    6. public:
    7. explicit testWidget(QWidget *parent = 0);
    8. QLabel test;
    9. QPushButton testButton;
    10.  
    11. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //testWidget.cpp
    2. testWidget::testWidget(QWidget *parent) :
    3. QWidget(parent)
    4. {
    5. setStyleSheet("background-color: yellow");
    6.  
    7. test.setText("test label");
    8. test.setParent(this);
    9. test.setVisible(true);
    10.  
    11. testButton.setText("TestButton");
    12. testButton.setParent(this);
    13. testButton.move(0, 20);
    14. testButton.setVisible(true);
    15. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //mainWindow.h
    2. class mainWindow : public QMainWindow
    3. {
    4. Q_OBJECT
    5.  
    6. public:
    7. explicit mainWindow(QWidget *parent = 0);
    8. testWidget *testW;
    9. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //mainWindow.cpp
    2. mainWindow::mainWindow(QWidget *parent)
    3. : QMainWindow(parent)
    4. {
    5. setFixedSize(1000, 900);
    6.  
    7. QLabel *test = new QLabel;
    8. test->setFixedSize(500,900);
    9. test->setStyleSheet("background-color: black;");
    10. setCentralWidget(test);
    11.  
    12. testW = new testWidget;
    13.  
    14. QDockWidget *dock = new QDockWidget("DOCKTEST", this);
    15. dock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
    16. dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    17. dock->setWidget(testW);
    18. addDockWidget(Qt::RightDockWidgetArea, dock);
    19. }
    To copy to clipboard, switch view to plain text mode 

    The result is:
    1335632129-Capturedu2012-04-28185448.jpg

    And I want that :
    1335632129-Capturedu2012-04-28185455.jpg

    I don't know how to do that, and if I add 2 widgets in the QDockWidget, how can I only define the height value ? (maybe 2/3 for the first one, and 1/3 for the second one)

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

    Thanks in advance for your help,

  2. #2
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Resize a QDockWidget ? (Width)

    Have you tried this?
    Qt Code:
    1. setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum);
    2. setMinimumSize(/*whatever*/);
    3. setMaximumSize(/*whatever*/);
    4. //or:
    5. // setMinimumHeight(/*whatever*/);
    6. // setMinimumWidth(/*whatever*/);
    7. // same for Maximum
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2011
    Posts
    19
    Thanks
    4

    Default Re: Resize a QDockWidget ? (Width)

    Hi,

    If I put this, it works :
    Qt Code:
    1. //testWidget.cpp
    2. setMinimumWidth(500);
    To copy to clipboard, switch view to plain text mode 

    But if i add 2 widgets, for example, the first one (height : 700), and the second one (height : 200).

    How can I set this value ? If I use setMinimumHeight, widgets has the good value but can't be resizeable less...
    So I want to define the height and the widget can eventually be resized. It's just the default value, so, this can be change !

    Thanks for your help,

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,620
    Thanks
    13
    Thanked 1,592 Times in 1,520 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Resize a QDockWidget ? (Width)

    You have not asked Qt to do any sort of Layout Management so consequently it does not do any layout management. Widgets stay at the size and location you give them and nothing adjusts automatically. Here is a working example:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class Widget: public QWidget
    4. {
    5. Q_OBJECT
    6. public:
    7. Widget(QWidget *p = 0): QWidget(p) {
    8. QVBoxLayout *layout = new QVBoxLayout(this);
    9. layout->addWidget(new QLabel("A label", this));
    10. layout->addWidget(new QPushButton("A button", this));
    11. layout->addStretch();
    12. setLayout(layout);
    13. // setMinimumWidth(200); // experiment here if you want to constrain the size
    14. }
    15. };
    16.  
    17. class MainWindow: public QMainWindow {
    18. Q_OBJECT
    19. public:
    20. MainWindow(QWidget *p = 0): QMainWindow(p) {
    21. QWidget *central = new QWidget(this);
    22. central->setStyleSheet("* { background-color: blue; }");
    23. setCentralWidget(central);
    24.  
    25. QDockWidget *dw = new QDockWidget("DockWidget", this);
    26. dw->setWidget(new Widget(dw));
    27. addDockWidget(Qt::RightDockWidgetArea, dw);
    28. }
    29. };
    30.  
    31. int main(int argc, char *argv[])
    32. {
    33. QApplication app(argc, argv);
    34.  
    35. MainWindow m;
    36. m.resize(640, 480);
    37. m.show();
    38. return app.exec();
    39. }
    40. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2011
    Posts
    19
    Thanks
    4

    Default Re: Resize a QDockWidget ? (Width)

    It's true, i don't define a layout for the widget... It's done now.

    I have another problem, the first window has autofilbackground value to true, and a black background. So, the context menu of the QDockWidget is black, and I can't see the text... When I right click on the title bar of the QDockWidget, i have a context menu for set visible or not, the QDockWidget, (in clicking checkbox). This context menu have a background color black and a text color black too. So I can see it.
    How can i modify this parameter ?

    Thanks in advance for your help

  6. #6
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Resize a QDockWidget ? (Width)

    I'm not sure if I understand you correctly. But it seems to me that you could use the Style Selectors to change the appearance of only those widgets you want to change - and not their children:
    http://doc.qt.io/qt-4.8/http://qt-project.org/doc/qt-4.8/stylesheet-syntax.html

Similar Threads

  1. looking for QDockWidget type, but not take whole width/height
    By Thomas_Lerman in forum Qt Programming
    Replies: 0
    Last Post: 27th October 2011, 20:09
  2. the default width of QDockWidget
    By weixj2003ld in forum Qt Programming
    Replies: 2
    Last Post: 11th September 2011, 09:31
  3. simple question,set width of QTreewidget or QDockWidget
    By weixj2003ld in forum Qt Programming
    Replies: 0
    Last Post: 17th May 2010, 01:52
  4. Header Width of QDockWidget in Qt4.3.3?
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 8th February 2008, 09:11
  5. Replies: 2
    Last Post: 22nd January 2008, 16:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.