Skip to content
  • 0 Votes
    2 Posts
    13k Views
    M

    After scouring the web, it appears that the only way to do this is the very complex technique of subclassing the widget. It's easier to just put another button on it, but then I had the problem where I couldn't pass a hover event to the QPushButton underneath it. This lead me to learn the technique on StackOverflow of building an eventFilter.

  • 0 Votes
    2 Posts
    3k Views
    Chris KawaC

    The thing is that toolbars don't really display icons. They display widgets (that can have icons). By default when you add an action to a toolbar a QToolButton is created for it, but you are not limited to that and can add any widget e.g. an expanding line edit, combobox or a button with an icon and text. All of these can have different size policies, be expanding or have a custom stylesheet applied.
    All of this makes calculating such size not feasible because how would you calculate it if a widget can change its size.

    What I'm saying is that yours is a special, very specific case (with just icons), and as such you need to handle it yourself if you want to.

    To answer your questions:

    It's not one thing that adds the space. There are couple of aspects that can contribute. You can control some(or all?) of them with stylesheets e.g. set padding of the toolbar and toolbuttons to 0 and margins and borders of the toolbuttons. By default all of these depend on a style and will vary across computers. You also need to be careful to consider the size of the toolbar handle (if it's movable) as its size depends on the active style. You also need to consider that if the icon is narrower than the iconSize then there's gonna by space left anyway. nope, AFAIK it can vary from one item of the toolbar to another if you set it this way nope and just out of curiosity - why do you need that? The bar will display an arrow button that will let you see the overflowing items. Also such calculated size would be useless as the window can be resized and thus the toolbar too (unless you're doing some really fancy layout).
  • 0 Votes
    2 Posts
    2k Views
    mrjjM

    Hi

    I would say a Delegate would be the way to do it.
    Have a look at
    "Star Delegate Example"

    For your fancy hand, you can use
    QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor));
    QApplication::restoreOverrideCursor();

    Its also possible via the model
    http://daniel-albuschat.blogspot.dk/2009/09/setting-mouse-cursor-for-qts-item-views.html

  • 0 Votes
    2 Posts
    4k Views
    SGaistS

    Hi and welcome to devnet,

    Why not just call setIcon with your current icon ? No need for a style sheet

  • 0 Votes
    26 Posts
    15k Views
    A

    Good, glad ya got it sorted out. Sorry I've been super busy lately and haven't lurked the forums here. :)

  • 0 Votes
    1 Posts
    957 Views
    No one has replied
  • Qt icons

    General and Desktop
    1
    0 Votes
    1 Posts
    511 Views
    No one has replied
  • 0 Votes
    2 Posts
    4k Views
    Romain CR

    After all this time, I don't fin a way to do it properly.

    I'm using QML and it's fine now. For people intereested in, this is my QML component:

    import QtQuick 2.5
    import QtQuick.Controls 1.4
    import QtQuick.Controls.Styles 1.4

    Button
    {
    property color backgroundColor
    property alias tooltip : buttonAction.tooltip
    property string imageSource
    signal buttonClicked ( )

    action : buttonAction activeFocusOnPress : true Keys.onPressed : { if ( (event.key == Qt.Key_Return||event.key == Qt.Key_Enter) && activeFocus) { buttonClicked ( ); event.accepted = true; } } style : ButtonStyle { background: Rectangle { id : backgroundRectangle color : backgroundColor Rectangle { id : roundedRectangle color : control.pressed?Qt.darker(backgroundColor, 1.1):backgroundColor anchors.fill : parent radius : 10 scale : ( control.hovered||control.activeFocus )?1:0.9 Image { id : buttonImage anchors.fill: parent fillMode : Image.PreserveAspectFit source : imageSource } } } } Action { id : buttonAction onTriggered : buttonClicked () }

    }

  • 0 Votes
    1 Posts
    1k Views
    No one has replied
  • Icon Dialog

    QML and Qt Quick
    12
    0 Votes
    12 Posts
    8k Views
    HackSawH

    @p3c0 said in Icon Dialog:

    @didu Icon specified through RC_ICONS will not be available at runtime in the code. It is used to set the icon for the executable which is created after compiling.
    In your case you need to store the icon in Qt's Resource System by creating a .qrc file. After that it will be accessible from the code. Eg:

    app.setWindowIcon(QIcon("qrc:/images/logo.ico"));

    Another quick way to test it ls loading the ico file from a physical location. Eg:

    app.setWindowIcon(QIcon("D:/MyIcons/logo.ico"));

    The above should work too.
    But a more practical approach is to use the Resource files. More info here.

    I was facing a similar issue with the icon being loaded successfully from its physical location but not from the resource file. So I tried

    app.setWindowIcon(QIcon(":/Images/IconFile.ico"));

    where "qrc" is removed which worked seamlessly.

  • 0 Votes
    6 Posts
    16k Views
    M

    Deleting the output directory and rebuilding does not work.
    Now I created a new project and now it works.

    Thank You :)