PDA

View Full Version : QScrollbar has no geometry



Ini
29th January 2016, 19:13
QScrollArea *scrollArea = new QScrollArea();
qDebug() << scrollArea->verticalScrollBar()->geometry();

output:
QRect(0,0 100x30)

I debugged this at the end of mainwindow constructor where the widget with this scrollarea and scrollbar inside is already shown. So why it does not have the right geometry?
The QRect data is clearly wrong.

Must be a bug right?
Or does the scrollbar depend on OS and Qt has no data about it and debugs sizehint or something?

edit: seems like nothing is working for these returned QScrollbars of the function, even isVisible() returns always false.

ChrisW67
29th January 2016, 21:46
Inside the main window constructor, even at the end of it, the main window is not yet shown.
The geometry value you see is a rectangle of 100 by 30 pixels at 0,0: hardly "no geometry."
The scroll bar you create, and immediately report the geometry of, has no relationship to another widget. It is neither directly parented to one nor inserted into a layout. Its geometry and visibility are independent of any other widget. It has not been shown, so the geometry is of little meaning anyway.

Ini
29th January 2016, 21:51
1. where the widget with this scrollarea and scrollbar inside is already shown. Reread that pls
2. is 0,0,0,0 only no geoemtry? The geometry is completely wrong at a point where the scrollbar should have geoemtry data.
3. pls reeread point 1 it is shown!

I will post a little example in a few hours later here. But if you want you can easy try yourself. Just call ->geoemtry() on a scrollbar inside a widget which should have already geoemtry data. Im pretty sure it returns the same.

ChrisW67
30th January 2016, 00:04
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>

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"


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()

Ini
30th January 2016, 04:36
thank you for the example. I said i bring a example today but i had something else today sry. I will study you example today and reply then.

thank your for your answers