Results 1 to 7 of 7

Thread: how to detect when QTextEdit's content is too large to fit

  1. #1
    Join Date
    Dec 2007
    Posts
    20
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default how to detect when QTextEdit's content is too large to fit

    I wan't to detect to when the content is to large.
    For example: if my QTextEdit can show 4 lines of text, but it has 5 lines now.

    There should be a way, 'cause if Qt::ScrollBarAsNeeded is set, then when I reach the fifth line, QTextEdit has a Scrollbar. I tried to find the signal which is detected when Qt::ScrollBarAsNeeded is on, but I did'n find anything.

    Do you have any idea?

    giotto

  2. #2
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to detect when QTextEdit's content is too large to fit

    Perhaps you can use the signal textChanged() and in it to chek if QTextEdit::horizontalScrollBar() will return a valid pointer, if not then there is still no a scrollbar so the text is not too large.

  3. #3
    Join Date
    Dec 2007
    Posts
    20
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: how to detect when QTextEdit's content is too large to fit

    Quote Originally Posted by The Storm View Post
    Perhaps you can use the signal textChanged() and in it to chek if QTextEdit::horizontalScrollBar() will return a valid pointer, if not then there is still no a scrollbar so the text is not too large.
    Is there a way to check that the ponter is valid?
    Hmmmm, does this if I set Qt::ScrollBarAlwaysOff?
    Last edited by giotto; 17th January 2008 at 00:07.

  4. #4
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to detect when QTextEdit's content is too large to fit

    Dunno for the flags but the pointer you can check very easy
    Qt Code:
    1. if (horizontalScrollBar()) // The ponter is valid
    2. // some code...
    3. else // The pointer is not valid
    4. // some other code...
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Dec 2007
    Posts
    20
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: how to detect when QTextEdit's content is too large to fit

    Quote Originally Posted by The Storm View Post
    Dunno for the flags but the pointer you can check very easy
    Qt Code:
    1. if (horizontalScrollBar()) // The ponter is valid
    2. // some code...
    3. else // The pointer is not valid
    4. // some other code...
    To copy to clipboard, switch view to plain text mode 
    this if is always true....

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

    Default Re: how to detect when QTextEdit's content is too large to fit

    Because the bar is always there, it's just hidden. Check its value range instead or check if the bar isVisible().

  7. The following user says thank you to wysota for this useful post:

    giotto (17th January 2008)

  8. #7
    Join Date
    Dec 2007
    Posts
    20
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: how to detect when QTextEdit's content is too large to fit

    this is working solution

    Qt Code:
    1. connect(editor->verticalScrollBar(),SIGNAL(rangeChanged(int,int)),this,SLOT(echoNewRange(int,int)));
    To copy to clipboard, switch view to plain text mode 

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.