Results 1 to 5 of 5

Thread: How to use a QPolygon as a Pushbutton?

  1. #1
    Join Date
    Jun 2010
    Location
    India
    Posts
    5
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default How to use a QPolygon as a Pushbutton?

    Hi

    I have created a polygon using PolygonF class in a Graphics Scene. Now i want to use that polygon as a button/push button to perform or trigger some event.

    I am not able to figure out how can I use the full area of the polygon as a button.

    Any help is welcome.

    scene = new QGraphicsScene(0, 0, 730, 500, this);

    view = new QGraphicsView(scene, this);

    item = view->itemAt(130, 50);

    QPolygonF poly1;

    poly1 << QPointF(110, 80) << QPointF(170, 80) << QPointF(200, 130) << QPointF(170, 180) << QPointF(110, 180) << QPointF(80, 130) ;

    scene->addPolygon( poly1 , QPen(brush1, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin), QBrush(QColor(Qt::white)));

    QLinearGradient linearGradient(0, 0, 100, 100);

    linearGradient.setColorAt(0, QColor(140, 140, 140, 255));

    scene->setBackgroundBrush(linearGradient);

    view->setScene(scene);

    view->show();

    Thanks and Regards

    Manish.S

  2. #2
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: How to use a QPolygon as a Pushbutton?

    Hi,

    Maybe you can try out implementing QPushButton first and then making it's shape as a polygon. I mean try to implement something like the following;

    Qt Code:
    1. MyCustomPushButton : public QPushButton {
    2.  
    3. ...
    4. void drawControl(..) // reimplement this
    5. }
    To copy to clipboard, switch view to plain text mode 

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

    Manish.S (6th December 2010)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use a QPolygon as a Pushbutton?

    You need to reimplement mouse events for your scene item.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    Manish.S (6th December 2010)

  6. #4
    Join Date
    Jun 2010
    Location
    India
    Posts
    5
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to use a QPolygon as a Pushbutton?

    Hi

    Thanks for the replies. I would try and implement these.

    But i have a doubt.
    Will a mouse event work on a touch screen as well?

    Thanks and Regards

    Manish.S

  7. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use a QPolygon as a Pushbutton?

    Quote Originally Posted by Manish.S View Post
    Will a mouse event work on a touch screen as well?
    Yes. The touch screen really emulates a mouse.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    Manish.S (6th December 2010)

Similar Threads

  1. QPainterPath and QPolygon
    By Muz in forum Qt Programming
    Replies: 0
    Last Post: 18th September 2009, 07:16
  2. QPainterPath to reduced QPolygon
    By Lodorot in forum Qt Programming
    Replies: 0
    Last Post: 9th September 2009, 23:20
  3. Replies: 2
    Last Post: 24th January 2009, 08:11
  4. What really is a QPolygon...
    By giusepped in forum Qt Programming
    Replies: 11
    Last Post: 14th January 2009, 06:57
  5. QPolygon rotate
    By xgoan in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2007, 11:18

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.