Results 1 to 4 of 4

Thread: Can't see frames around widgets

  1. #1
    Join Date
    Aug 2011
    Posts
    33
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Can't see frames around widgets

    OK, here is what I'm trying to do.

    I want a different frame around my pushbuttons than the one they come with. I have a subclass of QPushButton with the extras added, including their own frame. I'm thinking that I can superimpose a QFrame widget around the QPushButton and set the QFrame parameters as I choose.

    Well, I just can't get the QFrames around the QPushButtons to appear.

    The "parent" parameter is ui->centralWedget

    What am I missing?

    Here is the code, first the header, then the source. it's not large.
    Qt Code:
    1. #ifndef BITBUTTON_H
    2. #define BITBUTTON_H
    3.  
    4. #include <QtCore>
    5.  
    6. class BitButton : public QPushButton
    7. {
    8. Q_OBJECT
    9. public:
    10. BitButton(int number, QWidget *parent);
    11. void bbToggle();
    12.  
    13. int bbId;
    14. int bbState;
    15. void setState(int state);
    16. void setGeometry(QRect& rect);
    17. QFrame *frame;
    18.  
    19. signals:
    20. void bbClicked();
    21.  
    22. private slots:
    23.  
    24. private:
    25. QString bbStyle[2];
    26. };
    27.  
    28. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include <BitButton.h>
    2.  
    3. BitButton::BitButton(int number, QWidget *parent)
    4. : QPushButton(parent)
    5. {
    6. bbId = number;
    7.  
    8. bbStyle[0] = "color: aqua; background-color: black;"
    9. "border-style: sunken; border-width: 3px;"
    10. "border-color: white;";
    11.  
    12. bbStyle[1] = "color: black; background-color: aqua";
    13.  
    14. frame = new QFrame(parent);
    15. frame->setFrameStyle(QFrame::Box | QFrame::Sunken);
    16. frame->setLineWidth(3);
    17.  
    18. QFont font;
    19. #ifdef Q_WS_WIN
    20. font.setPointSize(font.pointSize()+2);
    21. font.setFamily("Lucida Console");
    22. #endif
    23. #ifdef Q_WS_X11
    24. font.setFamily("Monospace");
    25. font.setPointSize(12);
    26. #endif
    27.  
    28. this->setFont(font);
    29. this->setState(0);
    30. }
    31.  
    32. void BitButton::setGeometry(QRect &rect)
    33. {
    34. QRect frameRect = QRect(rect.x()+2,
    35. rect.y()+2,
    36. rect.width()+2,
    37. rect.height()+2);
    38.  
    39. frame->setFrameRect(frameRect);
    40. QPushButton::setGeometry(rect);
    41. this->frame->show();
    42. }
    43.  
    44. void BitButton::bbToggle()
    45. {
    46. this->setState(bbState ^= 1);
    47. }
    48.  
    49. void BitButton::setState(int state)
    50. {
    51. bbState = state;
    52. this->setText(QString::number(state));
    53. this->setStyleSheet(bbStyle[state]);
    54. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Can't see frames around widgets

    "sunken" is not a valid border-style.

  3. #3
    Join Date
    Aug 2011
    Posts
    33
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can't see frames around widgets

    Thanks.

    I can see the frames now, but I can't access the widgets inside them.

  4. #4
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Can't see frames around widgets

    I think you can achieve the look that you want solely with style sheets:
    Qt Code:
    1. bbStyle[0] = "color : black; background-color : #d3d3d3; min-height : 25; min-width : 75; "
    2. "border-style: outset; font-weight : bold; border-width: 2 px; border-radius: 10 px; "
    3. "border-color: #d3d3d3; ";
    To copy to clipboard, switch view to plain text mode 
    Play around with the border-width & border-radius. Also try this:
    Qt Code:
    1. bbStyle[1] = "BitButton{ color : black; background-color : #d3d3d3; min-height : 25; min-width : 75; "
    2. "border-style: outset; font-weight : bold; border-width: 2 px; border-radius: 10 px; "
    3. "border-color: darkgray;} "
    4. "BitButton:hover { color : black; background-color: #54ff9f; border-color: #d3d3d3;}"
    5. "BitButton:pressed{background-color:red}";
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. slide of frames
    By vinayaka in forum Newbie
    Replies: 3
    Last Post: 18th July 2011, 06:50
  2. Replies: 1
    Last Post: 12th May 2011, 22:41
  3. Camera Frames in UI
    By Johncdy in forum Qt Programming
    Replies: 1
    Last Post: 14th March 2011, 02:03
  4. multiple frames/widgets interacting
    By sfabel in forum Newbie
    Replies: 0
    Last Post: 6th November 2009, 04:30
  5. Display frames
    By bmn in forum Qt Programming
    Replies: 1
    Last Post: 30th April 2008, 10:26

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.