Results 1 to 3 of 3

Thread: How to Highlight a PixMap?

  1. #1
    Join Date
    Sep 2013
    Posts
    20
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default How to Highlight a PixMap?

    I am trying to make a simple card game, and I want to highlight some card pixmap images as my mouse hovers over it. Then I want to click on that card. But, lets take it one thing at a time. How would I highlight those cards, I really do not have any clue?

    By the way, I use QLabel to make the pixmaps.

    Here is the code, displaying my constructor and the function where I map the images.

    Qt Code:
    1. #include <QtWidgets>
    2. #include <string>
    3.  
    4. using std::string;
    5.  
    6. #include "canvas.h"
    7. #include "player.h"
    8. #include "computer.h"
    9.  
    10. Canvas::Canvas(QWidget *parent) : QWidget(parent)
    11. {
    12. cardTable = new QListView;
    13.  
    14. startButton = new QPushButton("Start");
    15. startButton->setFixedWidth(100);
    16.  
    17. connect(startButton, SIGNAL(clicked()), this, SLOT(startClicked()));
    18. connect(cardTable, SIGNAL(clicked(QModelIndex)), this, SLOT(currentCard(const QModelIndex &)));
    19.  
    20. QVBoxLayout *verticalLayout = new QVBoxLayout;
    21. verticalLayout->addWidget(cardTable);
    22. verticalLayout->addWidget(startButton);
    23.  
    24. QGridLayout *mainLayout = new QGridLayout;
    25. mainLayout->addLayout(verticalLayout, 0, 0, 1, 1);
    26.  
    27. setLayout(mainLayout);
    28.  
    29. setUpComputerIcons();
    30. setUpDeckIcons();
    31.  
    32. myGame = new Game(this);
    33. }
    34.  
    35. void Canvas::setUpPlayerIcons(string *pString)
    36. {
    37. QPixmap qpx;
    38. QSize iconSize;
    39. string str;
    40.  
    41. for (int i = 0; i < MAXCARDS; i++)
    42. {
    43. cardIconPlayer[i] = new QLabel(cardTable);
    44. str = pString[i];
    45. qpx = QPixmap(str.c_str());
    46. iconSize = qpx.size();
    47. iconSize.scale(190, 276, Qt::KeepAspectRatio);
    48. QPixmap scaledImage = qpx.scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    49. cardIconPlayer[i]->setPixmap(scaledImage);
    50. cardIconPlayer[i]->move(20 + 60 * i, 350);
    51. }
    52.  
    53. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to Highlight a PixMap?

    You could change the pixmap to a highlighted version, either by creating the highlighted pixmap from the original and using QPainter and some effect to create a new one or having two image files.

    Or you could try playing with the QPalette of the QLabels

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    LaTj (4th November 2013)

  4. #3
    Join Date
    Sep 2013
    Posts
    20
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to Highlight a PixMap?

    Thanks I used QGraphicsColorizeEffect::setColor(QPalette::Highli ght) for the QLabels;

    and I added a QRect outline to get the effect I wanted;

Similar Threads

  1. Find pixmap in pixmap
    By mizim in forum Newbie
    Replies: 4
    Last Post: 8th August 2012, 11:29
  2. Highlight of an ListView
    By Gihu in forum Qt Quick
    Replies: 1
    Last Post: 2nd July 2012, 17:13
  3. Replies: 1
    Last Post: 19th April 2011, 11:17
  4. highlight in QTextEdit
    By ubuntudevelop78 in forum Qt Programming
    Replies: 1
    Last Post: 27th November 2009, 00:22
  5. Highlight row in treeview
    By supergillis in forum Qt Programming
    Replies: 6
    Last Post: 20th November 2008, 08:49

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.