PDA

View Full Version : QLineEdit with QLineEdit:hover StyleSheet whle Mouse is Already Hovering



KineticArc
11th October 2010, 16:51
I have a QLineEdit on a simple configuration form that is checking for whether or not the QLineEdit contains a valid file system directory string. Whenever the user enters an incorrect directory path, I am changing the background color to yellow through a stylesheet, along with setting a hover stylesheet on the QLineEdit. Also, I change the image beside the line edit from a green check box to a red "X". The effect I want to obtain is achieved whenever the mouse is not already hovering over the QLineEdit. However, when the user enters into the line edit with the mouse, leaves the mouse hovering over the line edit, edits the contents, then tabs out of the line edit, the line edit becomes extremely small, and hovering over the line edit enlarges the box only to the size of the neighboring line edits. The line edit should be larger than its neighbors, while retaining its default size when the mouse is not hovering over it.

Some Example Code:

ConfigureForm.h:


class ConfigureForm : public QWidget, public Ui::wid_Configure
{
Q_OBJECT

public:
ConfigureForm(QWidget *parent = 0);

/// @note Going to skip some things to make this short...

private:
QString _execdir;
QString _path;
QString _binary;
QString _errorStyleSheet;
};


ConfigureForm.cpp:


ConfigureForm::ConfigureForm(QWidget *parent)
: QWidget(parent),
_errorStyleSheet("QLineEdit {background-color: yellow;} "\
"QLineEdit:hover {border: 1px solid #808080; "\
"background-color: yellow; "\
"border-radius: 4px;} ")
{
setupUi(this);

/// Set up signal/slot connection hidden for readability
}

void ConfigureForm::workingDirEdited()
{
if(le_WorkingDirectory->text() != _execdir)
{
QDir dir(le_WorkingDirectory->text())
if(!dir.exists())
{
le_WorkingDirectory->setStyleSheet(_errorStyleSheet);
}
}
}


I'm trying to scale back the code so it isn't a ton of code posted all at once. Basically, I want the line edit to look the same when the mouse isn't still hovering over it versus when it is hovering over it when the stylesheet has changed. I want the default look-and-feel of the QLineEdit on a Fedora 13 box running KDE, and when the mouse hovers over an in error QLineEdit, I want the mouse hover event to "magnify" the QLineEdit and expand the contents contained therein. Whenever the mouse ceases to hover over the line edit, I want all the defaults to return, except for the background color. The background color should stay yellow at all times when the line edit is in error, and whether or not the mouse is hovering over it.

If anyone needs pictures, I might be able to post a screenshot of what I mean when the box resizes while the mouse is hovering over it.

Also, anyone know how to load an external stylesheet and use only portions of its contents on a particular widget?

Thanks!

KineticArc
12th October 2010, 22:20
I found my problem. Reading the Qt documentation more thoroughly, I have found that QScrollArea::setWidget sets the widget's autoFillBackgroundProperty. After setting the widget, I simply called "i->_form->setAutoFillBackground(false);", and it fixed my issue.

Teaches me for not reading the setWidget method more thoroughly...