Results 1 to 4 of 4

Thread: LineEdit / SpinBox focus in problem

  1. #1
    Join Date
    Sep 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question LineEdit / SpinBox focus in problem

    Hi,
    I wanted to create custom spin box with following requirements:
    - before modified by user, it displays a custom (non-number) text
    - when focused (by mouse click), it selects all text, so simple input will overwrite the old one
    First I solved by using specialValueText and on the first change I erase it, but Im still struggling with the second... I tried to reimplement focusInEvent, but I never managed to take correct focus and text selected any idea?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: LineEdit / SpinBox focus in problem

    Could you show us what you've done so far?
    J-P Nurmi

  3. #3
    Join Date
    Sep 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: LineEdit / SpinBox focus in problem

    Everything I remember I tried:
    • subclass QSpinBox and reimplement its focusInEvent to do QSpinBox::focusInEvent and then selectAll
    • the same with just QLineEdit
    • tried to trick event by creating new event QEvent::FocusEvent with reason tab key (which behave the way I would like also click work) and in focusInEvent call QLineEdit::event with this new event
    • also I tried to follow QLineEdit::focusInEvent, but it is quite complicated and using staff from QLineEditPrivate class, which I dont know how to access from my subclassed class (and it is really nasty )
    • I created signal connected to selectAll slot and in focusInEvent was like QLineEdit::event and then emit my signal
    • default behavior of QAbstractSpinBox::focusInEvent looks quite simple
      Qt Code:
      1.  
      2. d->edit->event(event);
      3. if (event->reason() == Qt::TabFocusReason || event->reason() == Qt::BacktabFocusReason) {
      4. selectAll();
      5. }
      6. QWidget::focusInEvent(event);
      To copy to clipboard, switch view to plain text mode 
      I tried to rewrite this into my subclass' focusInEvent (without first line) and add MouseFocusReason into condition

    nothing worked
    If you're interested how whole class looks like, it is simple subclassed QSpinBox... i needed also reimplement sizeHint, becouse default one is bugged (i guess) and doesnt correctly calculate size for specialTextValue
    Last edited by Sethest; 15th September 2008 at 14:14.

  4. #4
    Join Date
    Sep 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: LineEdit / SpinBox focus in problem

    oh, and if it can somehow affect the problem, this subclassed spinbox is used as part of subclassed QDialog

Similar Threads

  1. QDialog derived and focus problem
    By elm66 in forum Qt Programming
    Replies: 1
    Last Post: 4th April 2008, 22:52
  2. QX11EmbedContainer problem with focus
    By PhoenixRevived in forum Qt Programming
    Replies: 0
    Last Post: 14th November 2007, 06:34
  3. QGraphicsTextItem focus problem
    By Gopala Krishna in forum Qt Programming
    Replies: 5
    Last Post: 26th June 2007, 18:25
  4. Tab/Enter focus problem
    By b1 in forum Qt Programming
    Replies: 4
    Last Post: 24th October 2006, 00:34
  5. problem with spinbox control ?
    By vinod in forum Qt Programming
    Replies: 3
    Last Post: 19th April 2006, 20:58

Tags for this Thread

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.