Results 1 to 3 of 3

Thread: Painting Faded away when alt key pressed,

  1. #1
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Painting Faded away when alt key pressed,

    Hi Friends,

    I am using Qt 4.2 in Windows,

    I am using ItemDelegate for ListWidget item , within that I am painting text and images as items using painter , If i press alt key or if i drag the mouse with in that listwiget,then all the list items are fading away,
    How can i prevent this?

    If anybody knows Please help me.

    Thanks,
    Rajesh.S

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Painting Faded away when alt key pressed,

    Is it a QItemDelegate subclass? Could we see the code of paint()?
    J-P Nurmi

  3. #3
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Painting Faded away when alt key pressed,

    Yes, this is subclass of QItemDelegate , Like this i am using 4 delegates for 4 seperate listwidgets in my program, and i am setting the corresponing delegates to corresponding widgets in QMainWindow subclass,
    Qt Code:
    1. #include <QtGui>
    2. #include "DelegateForStationsList.h"
    3. #include<QRect>
    4. #include<QIcon>
    5. #include<QPixmap>
    6.  
    7. INT32 QDelegateForStationsList::x=0;
    8. INT32 QDelegateForStationsList::y=-25;
    9.  
    10. //////////////////////////////////////////////////////////////////////////////////////
    11. // Function : QDelegateForStationsList Constructor
    12. //
    13. // Parameters : *parent
    14. // IN Parameters:None
    15. // OUT Parameters:None
    16. //
    17. // Description : For initialization Purpose
    18. //
    19. //
    20. // Return : void
    21. // 0 in case of success
    22. // -1 in case of failure
    23. ///////////////////////////////////////////////////////////////////////////////////////
    24.  
    25. QDelegateForStationsList::QDelegateForStationsList(QObject *parent)
    26. : QItemDelegate(parent)
    27. {
    28.  
    29. }
    30.  
    31. //////////////////////////////////////////////////////////////////////////////////////
    32. // Function : paint
    33. //
    34. // Parameters : *painter,option,index
    35. // IN Parameters:None
    36. // OUT Parameters:None
    37. //
    38. // Description : paints the elements into the listwidget in customized format
    39. //
    40. //
    41. // Return : void
    42. // 0 in case of success
    43. // -1 in case of failure
    44. ///////////////////////////////////////////////////////////////////////////////////////
    45.  
    46. void QDelegateForStationsList::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
    47. {
    48. painter->save();
    49. painter->restore();
    50. QString text = index.data(Qt::DisplayRole).toString();
    51. QIcon icon1 = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
    52. QPixmap pixmap1 = icon1.pixmap(option.decorationSize);
    53. QIcon icon2 = qvariant_cast<QIcon>(index.data(Qt::UserRole));
    54. QPixmap pixmap2 = icon2.pixmap(option.decorationSize);
    55.  
    56. drawDecoration(painter, option, QRect(x-5,y+17,30,30), pixmap1);
    57. QFont textFont;
    58. textFont.setFamily("Arial");
    59. textFont.setPixelSize(13);
    60. if((text=="Bad Breisig Hp")||(text=="Sinzig(Rhein)")||(text=="Remagen")||(text=="Oberwinter")||(text=="Bn-Bad Godesberg"))
    61. textFont.setBold(true);
    62. else
    63. textFont.setBold(false);
    64.  
    65. painter->setFont(textFont);
    66. painter->drawText(x+30,y+35,text);
    67.  
    68. if((text=="Sbk 23")||(text=="Sbk 367"))
    69. {
    70. painter->drawLine(280,y+17,273,y+24);
    71. painter->drawLine(273,y+24,280,y+31);
    72. painter->drawLine(280,y+31,273,y+38);
    73. painter->drawLine(273,y+38,280,y+45);
    74.  
    75. }
    76. y=y+25;
    77.  
    78. }
    79. //////////////////////////////////////////////////////////////////////////////////////
    80. // Function : reset
    81. //
    82. // Parameters : void
    83. // IN Parameters:None
    84. // OUT Parameters:None
    85. //
    86. // Description : resets the position for painting
    87. //
    88. //
    89. // Return : void
    90. // 0 in case of success
    91. // -1 in case of failure
    92. ///////////////////////////////////////////////////////////////////////////////////////
    93.  
    94. void QDelegateForStationsList::reset()
    95. {
    96. QDelegateForStationsList::x=0;
    97. QDelegateForStationsList::y=-25;
    98. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 4th July 2007 at 10:09. Reason: reformatted to look better

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.