Results 1 to 4 of 4

Thread: Seeking suggestions for a grid-based ASCII character layout

  1. #1
    Join Date
    Jan 2011
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Seeking suggestions for a grid-based ASCII character layout

    I am trying to lay out a Qt form as the UI for an ASCII character-based RPG. The UI elements will be arranged around a display region on the form. I would like a grid (perhaps 64x64) where each grid cell could display either an ASCII character or a sprite of some sort. I need the contents of each cell to fill the entire cell (no margins or padding). I would like the grid layout and its contents to expand/shrink as the form is re-sized.

    My first thought was to use a grid layout widget and populate it with a 64x64 grid of label controls. However, I can't seem to get simple text characters to scale properly - expanding to the edges of the cell, while not causing the size of the grid layout to change.

    I would appreciate suggestions on the best approach to accomplish this. Perhaps a grid layout widget isn't the best way to go?

    Thanks.
    Last edited by Quasimojo; 1st April 2012 at 22:15.

  2. #2
    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: Seeking suggestions for a grid-based ASCII character layout

    Use QGraphicsView or QtQuick.
    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.


  3. #3
    Join Date
    Jan 2011
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Seeking suggestions for a grid-based ASCII character layout

    Quote Originally Posted by wysota View Post
    Use QGraphicsView or QtQuick.
    Maybe the method of using the QGraphicsView to accomplish this just isn't apparent to me, but I don't see how that would produce the desired result. What I basically want is a grid of labels, the contents of which would each expand and shrink as the form is resized, maintaining the aspect ratio of the label contents. I think I've decided to go with a pixmap approach, rather than ASCII characters, but I still need to determine how to a) make the pics automatically resize to fit within the grid cells, and b) make them automatically resize to maintain their aspect ratio as the form is resized.

    Thanks.

  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: Seeking suggestions for a grid-based ASCII character layout

    Quote Originally Posted by Quasimojo View Post
    Maybe the method of using the QGraphicsView to accomplish this just isn't apparent to me, but I don't see how that would produce the desired result.
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class View : public QGraphicsView {
    4. public:
    5. View(QWidget *parent = 0) : QGraphicsView(parent) {}
    6. protected:
    7. void resizeEvent(QResizeEvent *e) {
    8. QGraphicsView::resizeEvent(e);
    9. fitInView(sceneRect(), Qt::KeepAspectRatio);
    10. }
    11. };
    12.  
    13. int main(int argc, char**argv) {
    14. QApplication app(argc, argv);
    15. View view;
    16. scene.setSceneRect(0,0,100,100);
    17. QFont f = view.font();
    18. f.setPointSize(3);
    19. for(int r = 0; r < 10; ++r) {
    20. for(int c = 0; c < 10; ++c) {
    21. QGraphicsSimpleTextItem *item = scene.addSimpleText(QString("%1-%2").arg(r).arg(c), f);
    22. item->setPos(c*10,r*10);
    23. }
    24. }
    25. view.setScene(&scene);
    26. view.resize(600,400);
    27. view.setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);
    28. view.show();
    29. return app.exec();
    30. }
    To copy to clipboard, switch view to plain text mode 
    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. The following user says thank you to wysota for this useful post:

    Quasimojo (3rd April 2012)

Similar Threads

  1. Replies: 14
    Last Post: 7th December 2011, 04:57
  2. Replies: 8
    Last Post: 14th April 2010, 06:54
  3. Suggestions for checkbox form layout
    By MrGarbage in forum Qt Tools
    Replies: 1
    Last Post: 26th July 2007, 00:07
  4. Suggestions Anyone:QTableView Grid
    By locus in forum Qt Programming
    Replies: 3
    Last Post: 23rd January 2007, 09:01
  5. Grid layout
    By nupul in forum Qt Programming
    Replies: 7
    Last Post: 21st April 2006, 22: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.