2 Attachment(s)
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
{
Q_OBJECT
public:
explicit testWidget
(QWidget *parent
= 0);
};
Code:
//testWidget.cpp
testWidget
::testWidget(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:
//mainWindow.h
{
Q_OBJECT
public:
explicit mainWindow
(QWidget *parent
= 0);
testWidget *testW;
};
Code:
//mainWindow.cpp
mainWindow
::mainWindow(QWidget *parent
){
setFixedSize(1000, 900);
test->setFixedSize(500,900);
test->setStyleSheet("background-color: black;");
setCentralWidget(test);
testW = new testWidget;
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
dock->setWidget(testW);
addDockWidget(Qt::RightDockWidgetArea, dock);
}
The result is:
Attachment 7650
And I want that :
Attachment 7651
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,
Re: Resize a QDockWidget ? (Width)
Have you tried this?
Code:
setMinimumSize(/*whatever*/);
setMaximumSize(/*whatever*/);
//or:
// setMinimumHeight(/*whatever*/);
// setMinimumWidth(/*whatever*/);
// same for Maximum
Re: Resize a QDockWidget ? (Width)
Hi,
If I put this, it works :
Code:
//testWidget.cpp
setMinimumWidth(500);
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,
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:
Code:
#include <QtGui>
{
Q_OBJECT
public:
layout
->addWidget
(new QLabel("A label",
this));
layout->addStretch();
setLayout(layout);
// setMinimumWidth(200); // experiment here if you want to constrain the size
}
};
Q_OBJECT
public:
central->setStyleSheet("* { background-color: blue; }");
setCentralWidget(central);
dw->setWidget(new Widget(dw));
addDockWidget(Qt::RightDockWidgetArea, dw);
}
};
int main(int argc, char *argv[])
{
MainWindow m;
m.resize(640, 480);
m.show();
return app.exec();
}
#include "main.moc"
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
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