Results 1 to 6 of 6

Thread: QPlainTextEdit ScrollBar problem

  1. #1
    Join Date
    Sep 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QPlainTextEdit ScrollBar problem

    I had a question, see these code first:

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.resize(500,500);
    QPlainTextEdit *text = new QPlainTextEdit(&w);
    QString str;
    for (int i = 0; i < 50; i++) {
    str += "text text text\n";
    }
    text->setGeometry(QRect(30,30, 200,200));
    text->setPlainText(str);
    qDebug() << "minimum: " << text->verticalScrollBar()->minimum();
    qDebug() << "maximum" << text->verticalScrollBar()->maximum();
    qDebug() << text->verticalScrollBar()->value();
    text->verticalScrollBar()->setValue(30);
    qDebug() << "show before value:" << text->verticalScrollBar()->value();

    w.show();
    qDebug() << "show after value:" << text->verticalScrollBar()->value();

    return a.exec();
    }

    The output result is :
    minimum: 0
    maximum 50
    0
    show before value: 30
    show after value: 0

    So, why the text->verticalScrollBar()->value() changed after the window show() ?

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QPlainTextEdit ScrollBar problem

    Because a widget is resized before it is shown

  3. #3
    Join Date
    Sep 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPlainTextEdit ScrollBar problem

    @tbscope Thank you for your answer.
    Is your meen the text widget is resized before it is shown?
    I changed the code like this:
    ...
    qDebug() << text->size();
    w.show();
    qDebug() << "show after value:" << text->verticalScrollBar()->value();
    qDebug() << text->size();

    The output result is:
    ...
    QSize(200, 200)
    show after value: 0
    QSize(200, 200)

    The size is same with before it is shown.
    so why?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPlainTextEdit ScrollBar problem

    Text layout is only calculated when required. It is required for the first time when the layout needs to be shown for the first time. It needs to be shown for the first time when the widget containing the document is shown for the first time. Only then the document size is calculated which influences the value of scrollbar.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPlainTextEdit ScrollBar problem

    Is that mean if I wan't to set the scrollbar value I must do it when the windows is shown?
    Is there any solusion to be set the scrollbar value when the windown is not shown?
    Thanks.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPlainTextEdit ScrollBar problem

    Quote Originally Posted by linuxsong View Post
    Is that mean if I wan't to set the scrollbar value I must do it when the windows is shown?
    After it is shown for the first time. It can be hidden when you do it, but it must have had been shown earlier.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 4
    Last Post: 17th April 2010, 03:42
  2. Problem with the scrollbar
    By mani_cbz in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 14th July 2009, 10:24
  3. how to control the scrollbar of QPlainTextEdit ?
    By csoapy in forum Qt Programming
    Replies: 4
    Last Post: 15th November 2008, 15:09
  4. Horizontal scrollbar problem
    By blaylockr in forum Newbie
    Replies: 2
    Last Post: 21st July 2008, 18:38
  5. Horizontal scrollbar tracking problem
    By tebessum in forum Qt Programming
    Replies: 1
    Last Post: 24th December 2006, 00:15

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.