I debugged this at the end of mainwindow constructor where the widget with this scrollarea and scrollbar inside is already shown.
As I explained, at the end of the constructor the main window is Not shown. If you debugged when the main window was shown then it cannot have been a breakpoint at the end of the constructor. You cannot have it both ways. Which is it?
In any case, in the example code you posted the QScrollBar is constructed as a top-level widget and immediately queried with no intervening attempt to show() the widget. This scroll bar is not visible at this point. This scroll bar has no relationship to the scrollbar that may appear when a QScrollArea is active.
2. is 0,0,0,0 only no geoemtry? The geometry is completely wrong at a point where the scrollbar should have geoemtry data.
I would expect "no geometry" to correspond to a null QRect; something the function has clearly not returned. I think you will find the value returned is some internal default value for the default constructed scroll bar.
In any case, you have not explained why you think this is not correct.
3. pls reeread point 1 it is shown!
I read and comprehended your words. Unfortunately they are inconsistent. Please read the top of this post.
#include <QApplication>
#include <QMainWindow>
#include <QWidget>
#include <QScrollBar>
#include <QScrollArea>
#include <QTimer>
#include <QDebug>
{
Q_OBJECT
public:
qDebug() << ">>" << Q_FUNC_INFO;
scrollContent->resize(500, 500);
area->setWidget(scrollContent);
resize(1000, 300); // should force vertical scroll bar but no horizontal.
setCentralWidget(area);
// Geometries returned but not meaningful because not visible
qDebug() << "Main window :"
<< isVisible() << geometry();
qDebug() << "Scroll area horizontal scroll bar:"
<< area->horizontalScrollBar()->isVisible()
<< area->horizontalScrollBar()->geometry();
qDebug() << "Scroll area vertical scroll bar :"
<< area->verticalScrollBar()->isVisible()
<< area->verticalScrollBar()->geometry();
// Your unrelated scroll area
qDebug() << "Unrelated scroll area :"
<< scrollArea->verticalScrollBar()->isVisible()
<< scrollArea->verticalScrollBar()->geometry();
delete scrollArea;
QTimer::singleShot(0,
this,
SLOT(afterShow
()));
qDebug() << "<<" << Q_FUNC_INFO;
}
private slots:
void afterShow()
{
qDebug() << ">>" << Q_FUNC_INFO;
// Main window visible, layout done, geometries meaningful
qDebug() << "Main window :"
<< isVisible() << geometry();
qDebug() << "Scroll area horizontal scroll bar:"
<< area->horizontalScrollBar()->isVisible()
<< area->horizontalScrollBar()->geometry();
qDebug() << "Scroll area vertical scroll bar :"
<< area->verticalScrollBar()->isVisible()
<< area->verticalScrollBar()->geometry();
// Your unrelated scroll area
qDebug() << "Unrelated scroll area :"
<< scrollArea->verticalScrollBar()->isVisible()
<< scrollArea->verticalScrollBar()->geometry();
delete scrollArea;
qDebug() << "<<" << Q_FUNC_INFO;
}
private:
};
int main(int argc, char **argv)
{
MainWindow w;
w.show();
return app.exec();
}
#include "main.moc"
#include <QApplication>
#include <QMainWindow>
#include <QWidget>
#include <QScrollBar>
#include <QScrollArea>
#include <QTimer>
#include <QDebug>
class MainWindow: public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *p = 0): QMainWindow(p) {
qDebug() << ">>" << Q_FUNC_INFO;
area = new QScrollArea(this);
QWidget *scrollContent = new QWidget(this);
scrollContent->resize(500, 500);
area->setWidget(scrollContent);
resize(1000, 300); // should force vertical scroll bar but no horizontal.
setCentralWidget(area);
// Geometries returned but not meaningful because not visible
qDebug() << "Main window :"
<< isVisible() << geometry();
qDebug() << "Scroll area horizontal scroll bar:"
<< area->horizontalScrollBar()->isVisible()
<< area->horizontalScrollBar()->geometry();
qDebug() << "Scroll area vertical scroll bar :"
<< area->verticalScrollBar()->isVisible()
<< area->verticalScrollBar()->geometry();
// Your unrelated scroll area
QScrollArea *scrollArea = new QScrollArea();
qDebug() << "Unrelated scroll area :"
<< scrollArea->verticalScrollBar()->isVisible()
<< scrollArea->verticalScrollBar()->geometry();
delete scrollArea;
QTimer::singleShot(0, this, SLOT(afterShow()));
qDebug() << "<<" << Q_FUNC_INFO;
}
private slots:
void afterShow()
{
qDebug() << ">>" << Q_FUNC_INFO;
// Main window visible, layout done, geometries meaningful
qDebug() << "Main window :"
<< isVisible() << geometry();
qDebug() << "Scroll area horizontal scroll bar:"
<< area->horizontalScrollBar()->isVisible()
<< area->horizontalScrollBar()->geometry();
qDebug() << "Scroll area vertical scroll bar :"
<< area->verticalScrollBar()->isVisible()
<< area->verticalScrollBar()->geometry();
// Your unrelated scroll area
QScrollArea *scrollArea = new QScrollArea();
qDebug() << "Unrelated scroll area :"
<< scrollArea->verticalScrollBar()->isVisible()
<< scrollArea->verticalScrollBar()->geometry();
delete scrollArea;
qDebug() << "<<" << Q_FUNC_INFO;
}
private:
QScrollArea *area;
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MainWindow w;
w.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Output:
>> MainWindow
::MainWindow(QWidget*)Main window
: false QRect(0,
0 1000x300
)Scroll area horizontal scroll bar
: false QRect(0,
0 100x30
)Scroll area vertical scroll bar
: false QRect(0,
0 100x30
)Unrelated scroll area
: false QRect(0,
0 100x30
)<< MainWindow
::MainWindow(QWidget*)>> void MainWindow::afterShow()
Main window
: true QRect(0,
0 1000x300
)Scroll area horizontal scroll bar
: false QRect(0,
0 983x17
)Scroll area vertical scroll bar
: true QRect(0,
0 17x300
)Unrelated scroll area
: false QRect(0,
0 100x30
)<< void MainWindow::afterShow()
>> MainWindow::MainWindow(QWidget*)
Main window : false QRect(0,0 1000x300)
Scroll area horizontal scroll bar: false QRect(0,0 100x30)
Scroll area vertical scroll bar : false QRect(0,0 100x30)
Unrelated scroll area : false QRect(0,0 100x30)
<< MainWindow::MainWindow(QWidget*)
>> void MainWindow::afterShow()
Main window : true QRect(0,0 1000x300)
Scroll area horizontal scroll bar: false QRect(0,0 983x17)
Scroll area vertical scroll bar : true QRect(0,0 17x300)
Unrelated scroll area : false QRect(0,0 100x30)
<< void MainWindow::afterShow()
To copy to clipboard, switch view to plain text mode
Bookmarks