Results 1 to 9 of 9

Thread: Design a commandline widget in Qt4?

  1. #1
    Join Date
    Jan 2008
    Posts
    14
    Thanks
    5

    Question Design a commandline widget in Qt4?

    Hi all,

    I am planning to code a commandline widget using Qt4. I don't know how many people here know Matlab. I want to have a input window just like Matlab has. That is, you can input/modify any text in current line before Enter is pressed. Once it becomes previous line, it is not editable anymore, but only displayed on the widget.

    Is QTextEdit capable of doing this? I read through the manual but with no found. Several `search' attempts also returned nothing on our forum. I am now open to any suggestion.

    Thank you in advance.

  2. #2
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Design a commandline widget in Qt4?

    You could simply use two QTextEdits, one containing the already issued commands and one to edit the current command. Then you can set the first one readonly with QTextEdit::setReadOnly(). To connect the two QTextEdits, have a look at the QTextEdit::append() slot, for example.

  3. The following user says thank you to rexi for this useful post:

    Ran (5th January 2009)

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

    Default Re: Design a commandline widget in Qt4?

    I'd say QLineEdit will be better for the second line. You can also use a single QTextEdit and reimplement keyPressEvent to handle the up key.

  5. #4
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Design a commandline widget in Qt4?

    Agreed, QLineEdit would probably be better for the editable one.

    But how would handling the up key help (I guess by handle you mean disable)? There's still the "left" key, or the user could click anywhere in the textedit, or shortcuts like Ctrl+A. Just to name a few things that come to my mind to tamper with the textedit's contents. Never underestimate what a user can do with (or to) a program

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

    Default Re: Design a commandline widget in Qt4?

    The easiest way is to react on the positionChanged() signal and make sure the position is always only on the last line. There is also QTextDocument::cursorPositionChanged() which might be more useful. As for ways to abuse the suggested solution, there is a finite and small number of things the user can do in this situation so it's not hard to guard them all.

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

    Ran (5th January 2009)

  8. #6
    Join Date
    Jan 2008
    Posts
    14
    Thanks
    5

    Default Re: Design a commandline widget in Qt4?

    Thanks, guys.

    Yes, I can simply use two QTextEdit widget. But I don't feel this is the most nice look for put two QTextEdit together. I might go with wysota's suggestion to handle the positionChanged() signal which, I think, is better for now.

  9. #7
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Design a commandline widget in Qt4?

    Just for completeness: you can disable the seperate frames of the textboxes and place them in a single, shared QFrame. That should make them visually indistinguishable.

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

    Default Re: Design a commandline widget in Qt4?

    Quote Originally Posted by rexi View Post
    Just for completeness: you can disable the seperate frames of the textboxes and place them in a single, shared QFrame. That should make them visually indistinguishable.
    The difference will be visible once the scrollbar appears.

  11. #9
    Join Date
    Jan 2008
    Posts
    14
    Thanks
    5

    Default Re: Design a commandline widget in Qt4?

    Yes. That's right. It's still visible once it has some content.

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. Widget Focus
    By navi1084 in forum Qt Programming
    Replies: 6
    Last Post: 29th September 2008, 10:22
  3. Playbutton functionality
    By uchennaanyanwu in forum Qt Programming
    Replies: 5
    Last Post: 31st July 2008, 22:29
  4. How to Open & Close a Widget ?!!
    By Fatla in forum Qt Programming
    Replies: 6
    Last Post: 13th June 2008, 20:39
  5. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35

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.