Results 1 to 3 of 3

Thread: PyQt5 Best way to draw a grid

  1. #1
    Join Date
    Apr 2021
    Qt products

    Default PyQt5 Best way to draw a grid

    Hi to everybody
    I'm new of QT world so I need your help.

    What is the best way to draw the grids like the ones in the image?


    In the version A: I have a single row grid composed by square or rectangular elements (each one with an ID) all of the same size. Over the row I need to put another row that counts the elements and a row with some DESC label (the element that contains the DESC label should have a size that is a multiple of the square element size).

    Each row should to go on a newline in someway (max square per row or simply when dimension reach the max size of the container)

    With a toggle button I should toggle the view in version B.

    In the version B: I have a grid of multiple row like the version A. The number line and the desc line is present only one time in each view.

    In both version:

    Every square should be clickable, when I click I can:

    1. modify background colour
    2. associate a text to the square that is indicated with a star put into square.

    Text and colour information will be stored in a database sqlite.

    What kind of method is the best? A Table with cellspan? A row of QRect? Other ojbects from QT library?

    Thank you

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 864 Times in 851 Posts
    Qt products

    Default Re: PyQt5 Best way to draw a grid

    I would probably do this using the Qt Graphics / View framework. You make a rectangle that is the outline of the entire grind, then you place a series of rectangles inside this outer rectangle as children. Text and stars are children of these inner rectangles. Look at QGraphicsRectItem, QGraphicsPolygonItem, and QGraphicsTextItem.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Apr 2021
    Qt products

    Default Re: PyQt5 Best way to draw a grid

    Thank you, I will test it soon

Similar Threads

  1. Replies: 2
    Last Post: 4th September 2014, 12:09
  2. Draw Grid lines with Painter
    By mechsin in forum Newbie
    Replies: 8
    Last Post: 3rd February 2013, 15:33
  3. Draw grid in QListView
    By woodtluk in forum Qt Programming
    Replies: 2
    Last Post: 22nd September 2010, 14:54
  4. Cant't draw custom grid
    By Tottish in forum Qwt
    Replies: 4
    Last Post: 1st May 2010, 10:55
  5. Replies: 5
    Last Post: 21st January 2010, 16:55

Tags for this Thread


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.