Results 1 to 2 of 2

Thread: Help with the basics setting up a Qt Gui

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2013
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Help with the basics setting up a Qt Gui

    Hi all!

    I'm really just getting started with Qt and learning the basics. Historically I've only ever really done Command Line driven stuff, with minimal event drivers.

    I wrote a Sudoku Solver in C++ (big whoop I know, but we all started somewhere!). I'd trying to put a Gui together, but I'm really struggling with the basics here. I'd like to set up a 9x9 grid where such that I can display the results of my solver. I thought of using QTableWidget for this, but that was a bit a of a disaster. I thought about doing just a simple matrix of 81 text boxes but can't understand how the gridlayout widget works (is it just me or does a lot of the Qt documentation leave a lot of to be desired - a few examples surely wouldn't kill them). Also - with the 81 text boxes approach, it seems so in-elegant.

    Anyway, I thought I'd appeal to the good nature of the coding community and say that I'd really appreciate some handholding.

    Thank you in anticipation of your help!

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Help with the basics setting up a Qt Gui

    I hope you will find it useful
    Qt Code:
    1. #include <QtCore>
    2. #include <QtWidgets>
    3.  
    4. int main(int argc, char * argv[])
    5. {
    6. QApplication app(argc,argv);
    7.  
    8. QWidget mainWidget;
    9. mainWidget.setWindowTitle("3x3x3x3");
    10.  
    11. QGridLayout * mainLayout = new QGridLayout(&mainWidget);
    12. mainLayout->setSpacing(0);
    13.  
    14. for(int mr = 0; mr < 3; mr++)
    15. {
    16. for(int mc = 0; mc < 3; mc++)
    17. {
    18. QFrame * widget = new QFrame;
    19. widget->setFrameStyle(QFrame::Plain);
    20. widget->setFrameShape(QFrame::Box);
    21.  
    22. QGridLayout * gridLayout = new QGridLayout(widget);
    23. gridLayout->setSpacing(0);
    24. gridLayout->setMargin(0);
    25.  
    26. for(int r = 0; r < 3; r++)
    27. {
    28. for(int c = 0; c < 3; c++)
    29. {
    30. QLabel * tile = new QLabel("X");
    31. tile->setFrameStyle(QFrame::Plain);
    32. tile->setFrameShape(QFrame::Box);
    33. tile->setMargin(5);
    34.  
    35. gridLayout->addWidget(tile, r, c, 1, 1, Qt::AlignCenter);
    36. }
    37. }
    38.  
    39. mainLayout->addWidget(widget, mr, mc, 1, 1, Qt::AlignCenter);
    40. }
    41. }
    42.  
    43. mainWidget.show();
    44.  
    45. return app.exec();
    46. }
    47.  
    48. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

    3x3x3x3.jpg
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. The very basics
    By KingOfHeart in forum Qt Programming
    Replies: 3
    Last Post: 18th May 2011, 19:43
  2. Replies: 5
    Last Post: 19th August 2008, 15:42
  3. Basics of Encryption and decryption
    By vermarajeev in forum General Discussion
    Replies: 4
    Last Post: 26th April 2007, 11:53
  4. Basics
    By Gayathri in forum Newbie
    Replies: 2
    Last Post: 17th November 2006, 11:14
  5. Pleaz.... im on the Basics!!
    By Jinesh in forum Qt Tools
    Replies: 2
    Last Post: 9th March 2006, 07:46

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
  •  
Qt is a trademark of The Qt Company.