Results 1 to 10 of 10

Thread: To fill diagnol of the table with the color other than the whole table.

  1. #1
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default To fill diagnol of the table with the color other than the whole table.

    Hi all
    I m having a table or say matrix of 16 rows and 16 columns on the widget ,
    on the widget there is also a qPushButton.

    When i click on the button the Timer starts and the whole tabe starts filling with the color say red,
    but i want the whole table fills with the red color except diagnol that is diagnol of the table fills with the different color say blue; How can I do this.

    Pls help


    Thanx
    Always Believe in Urself
    Merry

  2. #2
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: To fill diagnol of the table with the color other than the whole table.

    Well, maybe I don't understand well, but you just have to do a test before you repaint your cells, something like this :

    i -> row index
    j -> column index

    if i=j, set your color to blue
    else, set it to red.

    Am I wrong ?

  3. #3
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: To fill diagnol of the table with the color other than the whole table.

    Hi

    Might be u right , But i tried it remains unchanged
    ok take a look at the paint event I used and tell me in that where should I used this

    Qt Code:
    1. void CharacterWidget::paintEvent(QPaintEvent *ev)
    2. {
    3. QPainter p(this);
    4. QColor c;
    5. QBrush b;
    6. b.setStyle (Qt::Dense2Pattern);
    7. b.setColor(c);
    8. p.setBrush(b);
    9.  
    10. int coox = 0;
    11. int cooy = 0;
    12.  
    13.  
    14. for(int curr = 0; curr<= m_max; curr++)
    15. {
    16. if(m_value+1==curr)
    17. p.setBrush(Qt::white);
    18. p.setPen(Qt::cyan);
    19. p.drawRect(coox,cooy, squareSize, squareSize);
    20. QRectF rectangle(coox,cooy,squareSize, squareSize);
    21. coox += 16;
    22. if(coox+16>width())
    23. {
    24. coox = 0;
    25. cooy += 16;
    26. }
    27.  
    28. }
    29.  
    30. }
    To copy to clipboard, switch view to plain text mode 
    Always Believe in Urself
    Merry

  4. #4
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: To fill diagnol of the table with the color other than the whole table.

    Oh, ok, you've designed your own table widget, right ?

    I mean, you're not using QTableWidget / QTableView ?

  5. #5
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: To fill diagnol of the table with the color other than the whole table.

    Yaa I m not using QTableWidget/QTable View

    I m designing my own Table.

    So If u have any soln then pls tell me

    Thanx
    Always Believe in Urself
    Merry

  6. #6
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: To fill diagnol of the table with the color other than the whole table.

    Okay, the problem is quite different then

    You may add the same kind of test, it should work.
    This test will be within your 'for' instruction

    Qt Code:
    1. if (coox == cooy)
    2. {
    3. p.setBrush(Qt::white);
    4. p.setPen(Qt::blue);
    5. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: To fill diagnol of the table with the color other than the whole table.

    It wont works yaar....
    Always Believe in Urself
    Merry

  8. #8
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: To fill diagnol of the table with the color other than the whole table.

    Can you give me a sample code, so I can try to figure it out here ?

  9. #9
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: To fill diagnol of the table with the color other than the whole table.

    pls review the code..

    Qt Code:
    1. #include "characterwidget.h"
    2.  
    3. int coox ;
    4. int cooy ;
    5.  
    6.  
    7. QSize CharacterWidget::sizeHint() const
    8. {
    9. return QSize(m_max, m_max);
    10. }
    11.  
    12. void CharacterWidget::paintEvent(QPaintEvent *ev)
    13. {
    14. QPainter p(this);
    15. QColor c;
    16. QBrush b; //(Qt::cyan,Qt::ConicalGradientPattern)
    17. b.setStyle (Qt::Dense2Pattern);
    18. b.setColor(c); //Qt::cyan
    19. p.setBrush(b);
    20.  
    21. coox = 0;
    22. cooy = 0;
    23. for(int curr = 0; curr<= m_max; curr++)
    24. {
    25. if(m_value+1==curr)
    26. p.setBrush(Qt::white);
    27. p.setPen(Qt::cyan);
    28. p.drawRect(coox,cooy, squareSize, squareSize);
    29. QRectF rectangle(coox,cooy,squareSize, squareSize);
    30. coox += 16;
    31. if(coox+16>width())
    32. {
    33. coox = 0;
    34. cooy += 16;
    35. }
    36.  
    37. }
    38.  
    39. }
    40.  
    41. void CharacterWidget::timerEvent(QTimerEvent *ev)
    42. {
    43. if(ev->timerId()!=m_tim) return QWidget::timerEvent(ev);
    44. m_value++;
    45. update();
    46. if(m_value>=m_max)
    47. {
    48. stop();
    49. }
    50. }
    51.  
    52. void CharacterWidget::setMax(int m)
    53. {
    54. m_max = m;
    55. updateGeometry();
    56. }
    57. void CharacterWidget::setMin(int min)
    58. {
    59. m_min = min;
    60. updateGeometry();
    61. }
    62.  
    63.  
    64. void CharacterWidget::start()
    65. {
    66. m_tim = startTimer(300);
    67. }
    68. void CharacterWidget::stop()
    69. {
    70. killTimer(m_tim);
    71. m_tim = -1;
    72. }
    73.  
    74. void CharacterWidget::FillColor()
    75. {
    76. flag=true;
    77. start();
    78. update();
    79. }
    To copy to clipboard, switch view to plain text mode 

    If u understand this then tell me the soln.
    Always Believe in Urself
    Merry

  10. #10
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: To fill diagnol of the table with the color other than the whole table.

    Well, I meant a compilable one, so I can test it directly on my computer

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.