Results 1 to 5 of 5

Thread: Text shifts when control appears...

  1. #1
    Join Date
    Mar 2007
    Posts
    74
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Text shifts when control appears...

    Hi,

    After spending way too much time on this annoying little
    problem I've decided to go to the experts..

    In Designer I have created this small custom control.
    It is a lineEdit with a left and right arrow (Pushbutton) at either
    end. Normally the arrows are hidden.

    When the control gets focus the arrows appear and clicking
    one results in the linedit text changing.

    This works fine. However if the text is sufficiently long then
    when the arrows appear the text shifts slightly to the left.

    I either want to keep the text from shifting, or perhaps
    there is a better design where the arrows appear translucently
    over the ends of the linedit without effecting the size of the
    edit control?

    Thank you!

    Mark
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    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: Text shifts when control appears...

    Change the contents rect of the lineedit using setContentsMargins - the line edit is only rendered inside the contents rect. Then you can add those arrows inside the lineedit but outside the contents rect. Of course this will make your edit field smaller regardless of the presence of arrows. An alternative is to use stylesheets and set padding on the line edit. Then you can place the arrows inside the box. And use tool buttons instead of push buttons.

    An alternative to that is to use QwwTextSpinBox:

  3. #3
    Join Date
    Mar 2007
    Posts
    74
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Text shifts when control appears...

    I tried both of your suggestions but the problem persists. The StyleSheet option seemed to have the most potential, but I cannot get that to operate any better. Perhaps I am
    missing something... I've attached my .ui..

    Mark
    Attached Files Attached Files

  4. #4
    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: Text shifts when control appears...

    You can't do what I meant in Designer. You have to do something that my (unpublished yet, see attachment for an image - it is a single widget derived from QLineEdit) line edit class does - it reduces the contentsRect from the right side to fit the button inside the widget. But you have to do that in hand written code an not Designer (unless of course you'll use one of my widgets that come with a Designer plugin).

    You'll have to reduce the contentsRect and reimplement the resizeEvent to position the buttons where you need them. All that without using a layout (that's why you reimplement resizeEvent).
    Attached Images Attached Images

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Text shifts when control appears...

    The stylesheet approach requires you to derive your widget from QLineEdit and use manual placement of the QToolButtons (or simple QWidgets) inside the QLineEdit. This you definetly can't do from within designer so you have to get your hands dirty with writing the code the good old way. You should read this very interresting post by Girish: http://labs.trolltech.com/blogs/2007...-clear-button/
    It worked quite fine for me.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30

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.