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. Creating a random shape in QCustomWidgets
Forum Updated to NodeBB v4.3 + New Features

Creating a random shape in QCustomWidgets

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 714 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
    MokJ
    wrote on last edited by
    #1

    it may sound a bit stupid but Is it possible to create a random shaped widget which could act like a button or label or a QListWidget ?
    for example I want to create a maple leaf which I want to use to display a few items and when I click on them it should do something . So is it possible !

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      Well to some degree yes.
      You can use
      http://doc.qt.io/qt-5/qwidget.html#setMask-1
      To clip it to a shape and use paintEvent to paint the
      image of said shape.
      A Label would be easy as it just draws some texts, but
      something like QListWidget would require more work but depending on
      what you are after, maybe a background image can get something like that.

      If you just want a leaf looking button, you can use use image and
      it just works. However, the bounding rect will be square and still trigger when you
      click outside of the leaf image but still inside its clientrect.

      alt text

      1 Reply Last reply
      2
      • KillerSmathK Offline
        KillerSmathK Offline
        KillerSmath
        wrote on last edited by
        #3

        @Mokj

        for completent what @mrjj said about custom widget:
        Shaped clock Qt Example - http://doc.qt.io/qt-5/qtwidgets-widgets-shapedclock-example.html

        @Computer Science Student - Brazil
        Web Developer and Researcher
        “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

        1 Reply Last reply
        2
        • M Offline
          M Offline
          MokJ
          wrote on last edited by
          #4

          thanks @mrjj what an effort you've put . I have set the image as you've suggested. Thanks a million.

          And thank you @KillerSmath

          1 Reply Last reply
          1

          • Login

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