Results 1 to 2 of 2

Thread: horizontalSlider and hidden widgets

  1. #1
    Join Date
    Mar 2013
    Posts
    45
    Thanks
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default horizontalSlider and hidden widgets

    hi

    i want that when horizontalSlider will change, widgets be Apparent or hidden .

    Qt Code:
    1. #include "addaward.h"
    2. #include "ui_addaward.h"
    3. #include "stringclass.h"
    4.  
    5. Addaward::Addaward(QWidget *parent) :
    6. QDialog(parent),
    7. ui(new Ui::Addaward)
    8. {
    9. ui->setupUi(this);
    10.  
    11. ui->label2->setHidden(true);
    12. ui->lineEdit_2->setHidden(true);
    13. // "a" is a int type
    14. a = ui->horizontalSlider->value();
    15. setVisiblity();
    16. }
    17.  
    18. Addaward::~Addaward()
    19. {
    20. delete ui;
    21. }
    22.  
    23. void Addaward::setVisiblity()
    24. {
    25. switch(a)
    26. {
    27. case 2:
    28. {
    29. ui->label2->setHidden(false);
    30. ui->lineEdit_2->setHidden(false);
    31. } break ;
    32.  
    33. }
    34. }
    To copy to clipboard, switch view to plain text mode 

    But it does not work !

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: horizontalSlider and hidden widgets

    There are no widgets on the screen during the constructor, so the slider has whatever it default value is (because the user cannot interact with it) and you are setting the widgets initial visibility only. Since you also do nothing to ensure that changes to the slider value trigger a rethink of the widget visibility after they are visible then their initial visibilty stays unchanged.

    You need to look at using a signal from the slider and a slot to update the visibility.

    BTW: "It doesn't work" is a very poor description of the problem.

Similar Threads

  1. hidden a QTreeWidgetItem
    By mattia in forum Newbie
    Replies: 6
    Last Post: 19th February 2014, 14:04
  2. QDockWidget partially hidden
    By zzz9 in forum Qt Programming
    Replies: 0
    Last Post: 26th November 2012, 13:47
  3. Widgets taking too much space hidden on a Layout
    By mrlinx in forum Qt Programming
    Replies: 5
    Last Post: 2nd September 2011, 00:19
  4. The delegated widgets become hidden
    By fulbay in forum Qt Programming
    Replies: 4
    Last Post: 20th December 2010, 12:53
  5. widgets behind hidden widgets not working
    By bpetty in forum Newbie
    Replies: 13
    Last Post: 7th September 2007, 20:23

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.