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] Add a search QLineEdit to a QTableView
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Add a search QLineEdit to a QTableView

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 4.4k 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.
  • F Offline
    F Offline
    frankiefrank
    wrote on last edited by
    #1

    I want to implement a basic search box for my QTableView. I'm looking for an elegant solution for placing the lineEdit in reference to the QTableView.

    One way I saw in the documentation was a composite widget (i.e. a QFrame and a layout that would contain both the QTableView and the QLineEdit) but it would be a refactoring hell to have all the table-view methods reimplemented on the level of the new widget.

    Another way I saw was to to just create a widget without a parent/layout and position it "manually" above the QTableView. But I feel like that would be really an ugly way to do it.

    Are there any other solutions I can consider?

    "Roads? Where we're going, we don't need roads."

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gmaro
      wrote on last edited by
      #2

      Hi,

      This might be a little bit a not-the-best-way but it's easy and quick:
      @
      SearchTableView : public QFrame
      {
      Q_OBJECT
      public:
      WrapperFrame( QWidget parent );
      (const) TableView
      getTableView() (const)

      private:
      TableView *view
      QLineEdit *lineEdit

      //rest of private stuff, search mechanics etc.
      }
      @
      That gives you definitely good layout management instead of absolute positioning.
      In that case you don't need to wrap all the TableView's functions and if need to use many them outside just take the pointer and do what you need.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        There is another solution. You can use a trick with style sheets to put the search widget inside the table view. What you do is add padding to the widget, and use the cleared out space to put your widget. There is an "example":http://labs.qt.nokia.com/2007/06/06/lineedit-with-a-clear-button/ around on how to put a push button inside a line edit. The principle is the same here.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          frankiefrank
          wrote on last edited by
          #4

          Thank you very much for your suggestions. Will look into them!

          "Roads? Where we're going, we don't need roads."

          1 Reply Last reply
          0

          • Login

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