Results 1 to 5 of 5

Thread: QScrollbar has no geometry

  1. #1
    Join Date
    Nov 2015
    Posts
    67

    Default QScrollbar has no geometry

    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.
    Last edited by Ini; 29th January 2016 at 18:48.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,593
    Thanks
    13
    Thanked 1,587 Times in 1,516 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QScrollbar has no geometry

    1. Inside the main window constructor, even at the end of it, the main window is not yet shown.
    2. The geometry value you see is a rectangle of 100 by 30 pixels at 0,0: hardly "no geometry."
    3. 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.

  3. #3
    Join Date
    Nov 2015
    Posts
    67

    Default Re: QScrollbar has no geometry

    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.
    Last edited by Ini; 29th January 2016 at 21:02.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,593
    Thanks
    13
    Thanked 1,587 Times in 1,516 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QScrollbar has no geometry

    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.

    Qt Code:
    1. #include <QApplication>
    2. #include <QMainWindow>
    3. #include <QWidget>
    4. #include <QScrollBar>
    5. #include <QScrollArea>
    6. #include <QTimer>
    7. #include <QDebug>
    8.  
    9. class MainWindow: public QMainWindow
    10. {
    11. Q_OBJECT
    12. public:
    13. MainWindow(QWidget *p = 0): QMainWindow(p) {
    14. qDebug() << ">>" << Q_FUNC_INFO;
    15. area = new QScrollArea(this);
    16. QWidget *scrollContent = new QWidget(this);
    17. scrollContent->resize(500, 500);
    18. area->setWidget(scrollContent);
    19. resize(1000, 300); // should force vertical scroll bar but no horizontal.
    20. setCentralWidget(area);
    21.  
    22. // Geometries returned but not meaningful because not visible
    23. qDebug() << "Main window :"
    24. << isVisible() << geometry();
    25. qDebug() << "Scroll area horizontal scroll bar:"
    26. << area->horizontalScrollBar()->isVisible()
    27. << area->horizontalScrollBar()->geometry();
    28. qDebug() << "Scroll area vertical scroll bar :"
    29. << area->verticalScrollBar()->isVisible()
    30. << area->verticalScrollBar()->geometry();
    31.  
    32. // Your unrelated scroll area
    33. QScrollArea *scrollArea = new QScrollArea();
    34. qDebug() << "Unrelated scroll area :"
    35. << scrollArea->verticalScrollBar()->isVisible()
    36. << scrollArea->verticalScrollBar()->geometry();
    37. delete scrollArea;
    38.  
    39. QTimer::singleShot(0, this, SLOT(afterShow()));
    40. qDebug() << "<<" << Q_FUNC_INFO;
    41. }
    42. private slots:
    43. void afterShow()
    44. {
    45. qDebug() << ">>" << Q_FUNC_INFO;
    46. // Main window visible, layout done, geometries meaningful
    47. qDebug() << "Main window :"
    48. << isVisible() << geometry();
    49. qDebug() << "Scroll area horizontal scroll bar:"
    50. << area->horizontalScrollBar()->isVisible()
    51. << area->horizontalScrollBar()->geometry();
    52. qDebug() << "Scroll area vertical scroll bar :"
    53. << area->verticalScrollBar()->isVisible()
    54. << area->verticalScrollBar()->geometry();
    55.  
    56. // Your unrelated scroll area
    57. QScrollArea *scrollArea = new QScrollArea();
    58. qDebug() << "Unrelated scroll area :"
    59. << scrollArea->verticalScrollBar()->isVisible()
    60. << scrollArea->verticalScrollBar()->geometry();
    61. delete scrollArea;
    62. qDebug() << "<<" << Q_FUNC_INFO;
    63. }
    64. private:
    65. QScrollArea *area;
    66. };
    67.  
    68. int main(int argc, char **argv)
    69. {
    70. QApplication app(argc, argv);
    71. MainWindow w;
    72. w.show();
    73. return app.exec();
    74. }
    75. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    Output:
    Qt Code:
    1. >> MainWindow::MainWindow(QWidget*)
    2. Main window : false QRect(0,0 1000x300)
    3. Scroll area horizontal scroll bar: false QRect(0,0 100x30)
    4. Scroll area vertical scroll bar : false QRect(0,0 100x30)
    5. Unrelated scroll area : false QRect(0,0 100x30)
    6. << MainWindow::MainWindow(QWidget*)
    7. >> void MainWindow::afterShow()
    8. Main window : true QRect(0,0 1000x300)
    9. Scroll area horizontal scroll bar: false QRect(0,0 983x17)
    10. Scroll area vertical scroll bar : true QRect(0,0 17x300)
    11. Unrelated scroll area : false QRect(0,0 100x30)
    12. << void MainWindow::afterShow()
    To copy to clipboard, switch view to plain text mode 
    Last edited by ChrisW67; 30th January 2016 at 02:09.

  5. #5
    Join Date
    Nov 2015
    Posts
    67

    Default Re: QScrollbar has no geometry

    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

Similar Threads

  1. Geometry of QWebElement
    By TeeT in forum Newbie
    Replies: 4
    Last Post: 17th April 2015, 15:48
  2. QPlainTextEdit and geometry
    By tuli in forum Qt Programming
    Replies: 2
    Last Post: 12th August 2014, 13:42
  3. frameGeometry vs Geometry
    By bossy in forum Newbie
    Replies: 4
    Last Post: 18th October 2013, 00:55
  4. Geometry shader with QT4.7
    By saraksh in forum General Programming
    Replies: 3
    Last Post: 28th March 2011, 16:40
  5. QGraphicsLayout::geometry()
    By isutruk in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2009, 15:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.