QIcon not actually generating variations for QToolButton?
-
I'm not sure I am following you on that one. How did you ensure of the deep copy ?
But you also didn't answer my question: do these two methods do in place modification ?wrote on 10 Sept 2019, 19:23 last edited by@sgaist cuz that's what my constructor does. it does this:
CPixels::CPixels(const CPixels& other) { *this = other; #if _QT_ { QImage& self(*this); self = other.copy(); } #endif }
if you're asking if "Lighten()" does in-place mod, then yes. what other method are you referring to?
-
Hi
You can add via
https://doc.qt.io/qt-5/qicon.html#addPixmap
for the various states.
And yes normally it does generate for the other states when assigned in
Designer so try add same pixmap to that role and see if it does darken it.wrote on 11 Sept 2019, 00:25 last edited by@mrjj it's not assigned in Designer, it's assigned in code
-
wrote on 11 Sept 2019, 00:33 last edited by
-
Lifetime Qt Championwrote on 11 Sept 2019, 06:07 last edited by mrjj 9 Nov 2019, 06:31
Hi
on/off is used for Checkable buttons.
pr default its shown via the frame when checked but could
also have another icon. like big fat checkmark :)Adding
icon.addFile(QStringLiteral(":/test.svg"), QSize(), QIcon::Normal, QIcon::Off);
also generates the other icons as i can later paint with them.
(in paintevent)
icon().paint(&p,rect(),Qt::AlignCenter, QIcon::Mode::Disabled, QIcon::State::Off); -
wrote on 11 Sept 2019, 14:10 last edited by
i'm using QToolButton, and QImages which have already been created. I'm not loading QIcons directly from files. How do i create a QIcon that i can then load into QToolButton, such that when the user clicks it, it shows a "darkened" or "pressed" image?
-
wrote on 11 Sept 2019, 23:24 last edited by davecotter
does nobody else create QIcons programmatically, to be used in QToolButton?
-
does nobody else create QIcons programmatically, to be used in QToolButton?
wrote on 24 Sept 2019, 13:11 last edited by ODБOïQImage img(":/Icon.png"); auto toolButton = new QToolButton(toolBar); toolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); auto act = new QAction(); act->setIcon(QPixmap::fromImage(img)); act->setText("text"); toolButton->setDefaultAction(act);
-
wrote on 24 Sept 2019, 15:47 last edited by
that code snip only adds in a single state (the up state). i have separate pngs for the down and disabled state that never get used. how do i cause my tool button to use those states?
-
that code snip only adds in a single state (the up state). i have separate pngs for the down and disabled state that never get used. how do i cause my tool button to use those states?
I believe you're looking for this.
-
wrote on 24 Sept 2019, 17:29 last edited by
@kshegunov that's literally the code i'm already using but it's not working. see the code snips at the start of this thread, am I doing it wrong?
-
@kshegunov that's literally the code i'm already using but it's not working. see the code snips at the start of this thread, am I doing it wrong?
Yeah, sorry. I think it worked for a push button. could you try that? I don't recall currently if it's supposed to work with the toolbar button, I remember recently doing something akin but it was a table delegate so I was drawing it manually.
EDIT:
I think my brain had gone on a vacation ...
What style are you using? Is it possible the style doesn't support that? I usually use Fusion (i.e. Qt drawing). -
wrote on 24 Sept 2019, 17:41 last edited by
-
not sure what you mean by "style", i'm just using Qt out of the box, i haven't specifically selected a "style".
unfortunately the "QPushButton" does not draw the icon as "pressed" either, it just darkens the background which is not what i want:
not sure what you mean by "style", i'm just using Qt out of the box, i haven't specifically selected a "style".
Judging by your screenshot you're using the native osx style.
From what I can see here: https://code.woboq.org/qt5/qtbase/src/widgets/styles/qcommonstyle.cpp.html#1700
The tool button only takes 3 icon states - active, disabled and normal. Selected isn't one of them. But that's for Fusion, I have no clue what goes in the native osx style. So first advice - switch to fusion and use Normal/Active to alternate between unpressed/pressed. If that's what you're expecting go back to the native style and see if the problem is there. If so I'd say it's either a bug or limitation of the native style's implementation. -
wrote on 24 Sept 2019, 18:00 last edited by
Fusion
is un-mac-like, so i would not want to use it. strangely, "active" seems to mean "focused". when i click in the button it does turn color as expected but if i track the mouse (keep holding) while dragging OFF the button, it should re-draw in it's UP state, but it doesn't. when i let go it should do the same, but it STAYS looking pressed. if i then click the volume slider, the button THEN draws in the UP state. am i just not getting how this is designed to work? -
wrote on 24 Sept 2019, 19:00 last edited by
here is a minimal (20k) project demonstrating the problem.
-
here is a minimal (20k) project demonstrating the problem.
@davecotter said in QIcon not actually generating variations for QToolButton?:
Fusion is un-mac-like, so i would not want to use it.
I meant it purely as an academic exercise, so to say.
@davecotter said in QIcon not actually generating variations for QToolButton?:
strangely, "active" seems to mean "focused". when i click in the button it does turn color as expected but if i track the mouse (keep holding) while dragging OFF the button, it should re-draw in it's UP state, but it doesn't. when i let go it should do the same, but it STAYS looking pressed. if i then click the volume slider, the button THEN draws in the UP state.
Well, that's odd. Unfortunately I have no answers for you here, sorry.
-
wrote on 25 Sept 2019, 21:45 last edited by
please vote for it / watch it, if you care. thanks.