Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, June 2007
Qt 4.3 Style sheets and QFrame: documentation bug?


Message 1 in thread

Hello, all!

Qt Assistant 4.3.0:
"QFrame: Supports the box model. Does not support the :hover pseudo-state."

---------------------- cut -------------------------

#include <QtGui>

int main( int argc, char **argv )
{
    QApplication app( argc, argv );
    QDialog dialog;
    QFrame w(&dialog);
    w.setFrameStyle( QFrame::StyledPanel );
    QVBoxLayout layout(&dialog);
    layout.addWidget(&w);
    w.setFixedHeight( 40 );
    w.setStyleSheet(
        "QFrame         { background-color: navy; }\n"
        "QFrame:hover   { background-color: green; }\n"
        "QFrame:pressed { background-color: red; }\n"
    );
    layout.addStretch(1);
    w.show();
    dialog.show();
    return app.exec();
}

---------------------- cut -------------------------

Compile & run -- you get a navy frame which turns to green if mouse is hovering.
But the "pressed" state is broken -- frame doesn't want to be red if you click.

--
 [ signature omitted ] 

Message 2 in thread

Ivan Kharin wrote:
> Hello, all!
> 
> Qt Assistant 4.3.0:
> "QFrame: Supports the box model. Does not support the :hover pseudo-state."
> 

Yes, QFrame supports hover (corrected in snapshots).

-- code snipped --
> 
> Compile & run -- you get a navy frame which turns to green if mouse is hovering.
> But the "pressed" state is broken -- frame doesn't want to be red if you click.
> 

"pressed" state won't work since a stock QFrame has no concept of 
"pressed". If it makes sense for your customized QFrame, then just set 
State_Pressed in the style option of your paintEvent.

Something like,
MyFrame::paintEvent()
{
     QStyleOptionFrameV2 opt;
     opt.init(this);
     if (pressed)
         opt.state |= QStyle::State_Pressed; // will become :pressed
     style()->drawPrimitive(PE_Frame, &opt, this);
}

Girish

--
 [ signature omitted ] 

Message 3 in thread

> "pressed" state won't work since a stock QFrame has no concept of
> "pressed". If it makes sense for your customized QFrame, then just set
> State_Pressed in the style option of your paintEvent.

UPDATE:

State_Pressed does not exist, only State_Sunken.

And QFrame use State_Sunken!!!

frame->setStyleSheet(
  "QFrame { background-color: navy; border: none; }\n"
  "QFrame:hover { background-color: green; }\n"
  "QFrame:pressed { background-color: red; }\n"
  "QFrame:hover:pressed { background-color: cyan; }\n"
);

with frame->setFrameShadow( QFrame::Plain );
QFrame is navy and changes to green if a mouse over it
(ignoring mouse clicks).

with frame->setFrameShadow( QFrame::Sunken );
QFrame is red and changes to cyan if a mouse over it
(ignoring clicks too).

Very strangely.


-- 
 [ signature omitted ]