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.
{
public:
explicit MainWindow
(QWidget * parent
= 0) , mSize(500, 400)
{
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.
height())));
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.
height())));
setCentralWidget(widget);
}
QSize sizeHint
(void) const {
return mSize;
}
private:
};
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.height())));
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.height())));
setCentralWidget(widget);
}
QSize sizeHint(void) const
{
return mSize;
}
private:
const QSize mSize;
};
To copy to clipboard, switch view to plain text mode
Bookmarks