Results 1 to 2 of 2

Thread: QLineEdit with QLineEdit:hover StyleSheet whle Mouse is Already Hovering

  1. #1
    Join Date
    Sep 2010
    Location
    Washington, PA
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default QLineEdit with QLineEdit:hover StyleSheet whle Mouse is Already Hovering

    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:
    Qt Code:
    1. class ConfigureForm : public QWidget, public Ui::wid_Configure
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. ConfigureForm(QWidget *parent = 0);
    7.  
    8. /// @note Going to skip some things to make this short...
    9.  
    10. private:
    11. QString _execdir;
    12. QString _path;
    13. QString _binary;
    14. QString _errorStyleSheet;
    15. };
    To copy to clipboard, switch view to plain text mode 


    ConfigureForm.cpp:

    Qt Code:
    1. ConfigureForm::ConfigureForm(QWidget *parent)
    2. : QWidget(parent),
    3. _errorStyleSheet("QLineEdit {background-color: yellow;} "\
    4. "QLineEdit:hover {border: 1px solid #808080; "\
    5. "background-color: yellow; "\
    6. "border-radius: 4px;} ")
    7. {
    8. setupUi(this);
    9.  
    10. /// Set up signal/slot connection hidden for readability
    11. }
    12.  
    13. void ConfigureForm::workingDirEdited()
    14. {
    15. if(le_WorkingDirectory->text() != _execdir)
    16. {
    17. QDir dir(le_WorkingDirectory->text())
    18. if(!dir.exists())
    19. {
    20. le_WorkingDirectory->setStyleSheet(_errorStyleSheet);
    21. }
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    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!

  2. #2
    Join Date
    Sep 2010
    Location
    Washington, PA
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QLineEdit with QLineEdit:hover StyleSheet whle Mouse is Already Hovering

    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...

Similar Threads

  1. QTableView paint row in stylesheet hover
    By estanisgeyer in forum Qt Programming
    Replies: 3
    Last Post: 23rd October 2012, 10:17
  2. Hover on mouse over while dragging
    By mooreaa in forum Qt Programming
    Replies: 3
    Last Post: 6th February 2010, 11:31
  3. Replies: 0
    Last Post: 16th July 2009, 16:58
  4. Mouse hovering or press event not working?
    By qtzcute in forum Newbie
    Replies: 11
    Last Post: 15th July 2009, 11:53
  5. Replies: 3
    Last Post: 28th January 2007, 18:24

Tags for this Thread

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.