[SOLVED] Buttons doesn't "activate"



  • Hi,

    I'm a beginning programmer and new to Qt , so the question might be stupid, but i follow the youtube tutorials from user "rootshell" and when i deploy any widget at mainwindow.ui it is enabled but it isn't "activated" in a sense that i can't click it (e.g. can't check the checkbox or radio button). The only way i can do that is when i use grabMouse (or e.g. grabKeyboard) function but when i try to use the same function on various buttons (e.g. grabMouse on radioButton and on radioButton_2) only the last one works (the others can't be checked). What's the problem here?
    I should add that in the properties window field "enabled" is checked, and when i additionally use setEnabled(true) function on buttons nothing changes... any help?
    P.S. I use Qt Creator 2.7.0

    Regards


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What OS are you on ? What version of Qt ?

    Do you have a minimal example of your code that doesn't do what you want ?



  • Hi,
    i work on windows 7, Qt Creator 2.7.0 based on Qt 5.0.2 (32bit).
    mainwindow.cpp
    @#include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    ui->pushButton->grabMouse();
    ui->pushButton->setText("close");
    connect(ui->horizontalSlider,SIGNAL(valueChanged(int)),
    ui->progressBar,SLOT(setValue(int)));
    ui->horizontalSlider->grabKeyboard();
    ui->radioButton->setEnabled(true);
    ui->radioButton_2->setEnabled(true);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }
    @
    in this case Push button does work (because i used grabMouse function) and slider reacts only for keyboard arrows, doesn't react for mouse. radio buttons doesn't do anything (doesn't "check" themselves). Also when i add grabMouse on radioButtons only the last assigned button works (e.g radioButton_2 does work, and push button and radioButton don't)
    Here's my window:
    http://imageshack.us/photo/my-images/443/34893757.png/?sa=0

    PS i set textname for radioButtons and starting point for progress bar (from 24% to 0%) from property window


  • Lifetime Qt Champion

    Removing the two grab functions:

    What do you expect from your close button ?
    Do you expect your slider to move using your keyboard before giving it focus with the mouse ? Which key are you using ?



  • well, when i removed the first one (pushButton->grabMouse) everything works ok,
    big thanks for help and sorry for taking your time :)


  • Lifetime Qt Champion

    grabMouse and grabKeyboard should only be used in specific conditions. Most of the time you won't need them at all.

    You're welcome !

    Don't forget to update the thread's title to solved so other forum users may know that a solution has been found :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.