Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to read the color of an rectitem

How to read the color of an rectitem

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mahesh
    wrote on last edited by
    #1

    hi,in my app i have a graphicsscene and lot of rectitems with different colours...i want to read the color of an perticular rectitem ... how to read the color of an rectitem ?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      QGraphicsRectItem is derived from QGraphicsShapeItem, which as properties called pen and brush. The first is used for the outline of the shape, the second for the fill. Both contain a color.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mahesh
        wrote on last edited by
        #3

        Thanks for the reply..i already done setBresh to the rectitem now my doubt is

        @
        QGraphicsRectItem *rectItem=new QGraphicsRectItem(20,30,40,50);
        rectItem->setBrush( QBrush(Qt::green));
        @
        i added color like this and then i added this rectitem to the scene...

        @void View ::mousePressEvent(QMouseEvent* event) {

        if (event->button() == Qt::LeftButton){

        if (QGraphicsRectItem *item = itemAt(event->pos())) {

        //here i have the rectitem i want to find the color of this item
        }

        }

        }
        @

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rokemoon
          wrote on last edited by
          #4

          First of all "itemAt":http://doc.qt.nokia.com/latest/qgraphicsview.html#itemAt return QGraphicsItem , so you shoud cast it to your QGraphicsRectItem and check pointer on null.
          @
          void View ::mousePressEvent(QMouseEvent
          event) {

          if (event->button() == Qt::LeftButton){
          QGraphicsRectItem *item = static_cast<QGraphicsRectItem *>(itemAt(event->pos()));
          if (item) {
          QBrush brush = item->brush(); // and so on
          //here i have the rectitem i want to find the color of this item
          }
          }
          }
          @
          Try it, I don't test it.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mahesh
            wrote on last edited by
            #5

            it is showing rgb format ...how can it convet it into name format(ex:blue,green)...

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              [quote author="phani438" date="1322222885"]it is showing rgb format ...how can it convet it into name format(ex:blue,green)...
              [/quote]

              Other than building your own table of rgb->name mappings, you can not.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved