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. How to make a "global/shared" widget
Forum Updated to NodeBB v4.3 + New Features

How to make a "global/shared" widget

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 849 Views 2 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.
  • D Offline
    D Offline
    DavidM29
    wrote on 19 Apr 2018, 07:39 last edited by
    #1

    Hello,

    First of all I'm quite new to C++ and Qt. I'm used to Java.
    I'm trying to make my first UI on Qt. I started with a StackedWidget because I want some kind of Home with buttons that open differents widgets.
    From here everything is ok.
    The problem is that I would like to have a common function on every widget. This widget would be at the top of the page and contains a label where I set date and time. At the moment I don't know how to achieve this.
    Here's what I've done for now :

    • MainWidget containing my StackedWidget
    • My StackedWidget contains 3 others widgets
    • I'm able to switch between my differents widget.

    What I'm not able to do is access the Labels I have in my others Widgets from my MainWidget in order to set the time as Text. I've already done the timer.

    I'm note sure that I've made myself clear.
    There is probably a problem in my app architecture, It's my first app and don't know what are the good practices.

    Thank for you help.

    J 1 Reply Last reply 19 Apr 2018, 09:00
    0
    • D DavidM29
      19 Apr 2018, 07:39

      Hello,

      First of all I'm quite new to C++ and Qt. I'm used to Java.
      I'm trying to make my first UI on Qt. I started with a StackedWidget because I want some kind of Home with buttons that open differents widgets.
      From here everything is ok.
      The problem is that I would like to have a common function on every widget. This widget would be at the top of the page and contains a label where I set date and time. At the moment I don't know how to achieve this.
      Here's what I've done for now :

      • MainWidget containing my StackedWidget
      • My StackedWidget contains 3 others widgets
      • I'm able to switch between my differents widget.

      What I'm not able to do is access the Labels I have in my others Widgets from my MainWidget in order to set the time as Text. I've already done the timer.

      I'm note sure that I've made myself clear.
      There is probably a problem in my app architecture, It's my first app and don't know what are the good practices.

      Thank for you help.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 19 Apr 2018, 09:00 last edited by
      #2

      @DavidM29 Add a setter method to your other widget to set the date/time:

      class MyWidget...
      {
      public:
          void setDateTime(const QDateTime&);
      }
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply 19 Apr 2018, 14:15
      2
      • J jsulm
        19 Apr 2018, 09:00

        @DavidM29 Add a setter method to your other widget to set the date/time:

        class MyWidget...
        {
        public:
            void setDateTime(const QDateTime&);
        }
        
        D Offline
        D Offline
        DavidM29
        wrote on 19 Apr 2018, 14:15 last edited by
        #3

        @jsulm
        I used your idea of creating a setter in each other widget. It worked but it forces me to setDate on every single widget. But it does the trick.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 19 Apr 2018, 19:59 last edited by SGaist
          #4

          Hi and welcome to devnet,

          Depending on what your other widgets are, you can create a base class that has that method and inherit your other widgets from it.

          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
          1

          1/4

          19 Apr 2018, 07:39

          • Login

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