PDA

View Full Version : QMainWindow setting normal size



mqt
12th July 2013, 10:50
Question 1.

I would like to start a main window maximized. I also want to allow the user to restore. When the user restores the window first time, I want the window to be a particular size, say 500*400. Later user may change the size with mouse. I am looking for something like resize() function which will not act immediately (currently it is Maximized view) and will act when viewNormal() is called or restore button is clicked.

Question 2.
Is there any way to get the size of maximized window when it is not actually maximized? The Desktop size gives the size without considering Window Task Bar and hence that height/widht is slightly larger than maximized window. I dont want to show the window maximized. But I want to do some calculations based on the hieght available for maximized window.

Santosh Reddy
12th July 2013, 11:23
In short the answer is yes to both the questions.

1. Implement sizeHint() function for mainwindow
2. Use qApp->desktop()->availableGeometry();

Here is an example.


class MainWindow : public QMainWindow
{
public:
explicit MainWindow(QWidget * parent = 0)
: QMainWindow(parent)
, mSize(500, 400)
{
QWidget * widget = new QWidget;
QVBoxLayout * layout = new QVBoxLayout(widget);

QRect r =qApp->desktop()->screenGeometry();
layout->addWidget(new QLabel(QString("Desktop : (%1,%2,%3,%4)").arg(r.x()).arg(r.y()).arg(r.width()).arg(r.heigh t())));

r =qApp->desktop()->availableGeometry();
layout->addWidget(new QLabel(QString("Usable : (%1,%2,%3,%4)").arg(r.x()).arg(r.y()).arg(r.width()).arg(r.heigh t())));

setCentralWidget(widget);
}

QSize sizeHint(void) const
{
return mSize;
}

private:
const QSize mSize;
};