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 :
[CODE]//testWidget.h
class testWidget : public QWidget
{
Q_OBJECTpublic:
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_OBJECTpublic:
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,
-
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.
-
You need to use Qt layout functionality if you want Qt to do anything to layout/resize the content of your widgets.