Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Adding onclick event to some Qwidget
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Adding onclick event to some Qwidget

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 10.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zarkon
    wrote on 20 Mar 2014, 19:43 last edited by
    #1

    Hi,

    I am relative new to Qt. I am going through some fast learning curve at the moment but there are some things I am stuck at.

    I have made a QT-cpp application with several widgets. It is actually meant to be a kind of wizard. It goes something like (pseudo code)

    @mainwindow->layout->addwidget(new headerWindow);
    QWidget *pWindow = new changeableWindow;
    mainwindow->layout->addwidget(pWindow);
    mainwindow->layout->addwidget(new buttonControlWindow);@

    to pWindow I have added another widget like this

    @QUiLoader loader;
    QWidget *formWidget;

    QFile file(":/forms/textfinder.ui");
    file.open(QFile::ReadOnly);

    formWidget = loader.load(&file, this);
    file.close();
    pWindow->layout->addwidget(formWidget);@

    I dont know exactly what is on formWidget, but when I click on a QSpinBox or QLineEdit I would like to perform some actions (execute a function). The normal signal/slot things dont seem to apply so I guess I have to work with events, but how?

    Greetings

    Jos

    1 Reply Last reply
    0
    • X Offline
      X Offline
      Xander84
      wrote on 20 Mar 2014, 20:15 last edited by
      #2

      to clarify you want to receive general click events even if the window widget contains other widgets like buttons etc and the user clicks on them?
      if you just want events for special widgets like a button or widgets that have a custom signal for it that would be easy i guess, click events might be consumed by the child widget and not passed to the main window but you can try that yourself when you implement the mouse event function in your window class:
      override the function QWidget::mouseReleaseEvent(QMouseEvent * event) and see if it gets called.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 20 Mar 2014, 20:32 last edited by
        #3

        Hi and welcome to devnet,

        Can you give an example of what you would like to do with that function ? e.g. : write in QLineEdit -> call myFunc -> validate content

        Since you want to do some kind of wizard, did you took a look at QWizard ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          Zarkon
          wrote on 21 Mar 2014, 07:28 last edited by
          #4

          Hi,

          Thanks for the hint about QWizard. That really helps. Although I had built already some infrastructure I was wrestling with layout problems all day.

          Anyway the problem is as follows. I making another program that uses some ui-files as an input. Since ui-files are just xml-files that define controls, we also need to provide an xml file with valid values. Like this:

          @<parameters>
          <comboBoxSpeed>
          <Value>2400</Value>
          <Value>4800</Value>
          <Value>9600</Value>
          <Value>19200</Value>
          <Value>38400</Value>
          <Value>115200</Value>
          </comboBoxSpeed>
          <comboBoxDataBits>
          <Value>5</Value>
          <Value>6</Value>
          <Value>7</Value>
          <Value>8</Value>
          </comboBoxDataBits>
          <comboBoxParity>
          <Value>None</Value>
          <Value>Even</Value>
          <Value>Odd</Value>
          <Value>Mark</Value>
          <Value>Space</Value>
          </comboBoxParity>
          <comboBoxStopBits>
          <Value>1</Value>
          <Value>2</Value>
          </comboBoxStopBits>
          </parameters>@

          comboBoxSpeed (like others) is control on the form. When I read this XML-file I set the valid values for this form. I have made this by hand, but it would be better if our customer could do it himself interactively. That's what the wizard will do. So if I select a QComboBox on the form it needs to highlight that QComboBox and a ComboBoxValidationWidget with valid values, default etc. will get called. The user sets the values and these are written to XML. Similar for QSpinBox and QLineEdit.

          If I re-implement QWidget::mouseReleaseEvent(QMouseEvent * event). How would I go about it? I need to process only widgets that have formWidget as parent. Or not?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 21 Mar 2014, 07:55 last edited by
            #5

            For the highlighting part you can use a QRubberBand

            As for editing, you could have a special mode for your application (e.g. like firebug for Firefox) where you have a transparent overlay widget that you would use to implement the mouse logic. The widget would grab the mouse, and each time you move it checks whether it can find an "editable" widget under, if so, show the QRubberBand on the widget. If the user clicks, start the correct editor.

            Hope it helps

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              Zarkon
              wrote on 21 Mar 2014, 08:23 last edited by
              #6

              I will investigate it. Thanks for comments. They have been very useful.

              1 Reply Last reply
              0

              1/6

              20 Mar 2014, 19:43

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved