Results 1 to 6 of 6

Thread: tool buttons on top of label

  1. #1
    Join Date
    Oct 2006
    Location
    Massachusetts, USA
    Posts
    19
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Question tool buttons on top of label

    I am looking for a simple way to place multiple tool buttons, laid out at arbitrary locations, on top of a label showing my pixmap. I plan to make the icons for the tool buttons semi-transparent, and set them to auto-raise, so that hovering over portions of the label will effectively highlight portions of its pixmap for the user to act on. Essentially, I want the user to be able to select a portion of a fixed picture by clicking a tool button. Once selected, I'll change either the underlying pixmap label or the tool button icon state to show the selection.

    My basic question is how to set up the button layout over a pixmap. I'd like to use Designer if possible, since I may have to lay out tool buttons on multiple images. I looked at setting a background image for a QGroupBox, but didn't see that option. I looked at QStackedLayout and QStackedWidget, but that seems to show pages mutually exclusively.

    This could reduce to a simple question: how to use Designer to lay out tool buttons on a label. (If so, perhaps I'm posting in the wrong forum.)

    Suggestions on tools and classes or alternative approaches would be great.

    thanks

  2. #2
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: tool buttons on top of label

    Since the buttons have static positions, then you should not use any layout manager. Just give them their static positions. This is easy in Designer. Create your label and set a pixmap for it. Then place toolbuttons where you want them. They will not be transparent in Designer (that's so you can see them), but you can use preview to see how it will behave.

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

    McKee (28th October 2008)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: tool buttons on top of label

    Maybe what you require is a toolbar with a pixmap set as its background?

  5. #4
    Join Date
    Oct 2006
    Location
    Massachusetts, USA
    Posts
    19
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: tool buttons on top of label

    Thank you both for good ideas. I am following recommendation of Brandybuck. That should work nicely.

  6. #5
    Join Date
    Oct 2006
    Location
    Massachusetts, USA
    Posts
    19
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: tool buttons on top of label

    ... just getting back to this task ...

    Now my challenge is to get the tool button not to paint a button background when it auto-raises. I want to control the pixmaps shown in QIcon::Normal and Active modes, and QIcon::Off and On states. My QToolbutton items are auto-raise and checkable. The underlying label pixmap shows through nicely when I set the tool button icon to be semi-transparent, as in

    Qt Code:
    1. QToolButton *tool_button = Ui.ToolButtonTest;
    2. QSize size = tool_button->size();
    3. tool_button->setIconSize(size - QSize(10,10));
    4. QPixmap pixmap(size);
    5. pixmap.fill(QColor(0,0,0,50));
    6. QIcon icon;
    7. icon.addPixmap(pixmap,QIcon::Active,QIcon::On);
    8. tool_button->setIcon(icon);
    To copy to clipboard, switch view to plain text mode 

    But the when the tool button auto-raises or is "checked", the style engine appears to paint a system style dependent frame and background that I cannot suppress. We normally want this behavior, but it's not what I want here. I tried changing every color role in the toolbutton's palette to a transparent color, which helped a little in some styles but is not robust or complete.

    Should I abandon QToolButton and create my own button subclass, re-implementing mouse events to create the auto-raise behavior I want? I was hoping to write a little less code and use Designer to just place tool buttons.

    I'm using Qt 4.3.3 on XP.

    Any suggestions?

    thanks

  7. #6
    Join Date
    Oct 2006
    Location
    Massachusetts, USA
    Posts
    19
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: tool buttons on top of label

    Oops. Never mind. The answer, of course, is Qt's Style Sheets. I got the effect I want by modifying each tool button's style sheet as follows.

    Qt Code:
    1. QToolButton:hover {border: 2px solid grey; border-radius: 12px}
    2. QToolButton:checked {border: 2px solid green; border-radius: 12px; background: rgba(0,0,0,25)}
    To copy to clipboard, switch view to plain text mode 

    I'm all set.

Similar Threads

  1. Tool Buttons...
    By csvivek in forum Qt Tools
    Replies: 1
    Last Post: 9th May 2008, 08:44
  2. tool tip for label
    By Seema Rao in forum Qt Programming
    Replies: 1
    Last Post: 21st April 2006, 14:22

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.